<commit_before>require "resourced/version"
require "resourced/attributes"
require "resourced/finders"

module Resourced
  module Resource
    module InstanceMethods
      def initialize(params, scope=nil)
        @scope = scope
        @model = self.class.instance_variable_get(:@model)
        @key   = self.class.instance_variable_get(:@key)
        @chain = @model
        super
      end
      attr_accessor :attributes, :scope
      attr_reader   :model, :chain, :key

      ##
      # Run external code in context of resource
      #
      # Examples:
      #
      #     resource = UserResource.new(params, scope)
      #     subj = "john"
      #     resource.context do
      #       chain.where(name: subj)
      #     end
      #
      def context(&block)
        if block_given?
          @chain = self.instance_eval(&block)
        end

        self
      end
    end

    module ClassMethods
      ##
      # Set or get model class
      #
      def model(model_class=nil)
        model_class ? @model = model_class : @model
      end

      ##
      # Duplicate resource and set another model class
      #
      def [](model_class)
        klass = self.dup
        klass.instance_variable_set(:@model, model_class)
        klass
      end

      ##
      # Set primary key
      #
      def key(key_name=nil)
        key_name ? @key = key_name.to_sym : @key
      end
    end

    def self.included(base)
      base.send(:include, Resourced::Attributes)
      base.send(:include, Resourced::Finders)
      base.send(:include, InstanceMethods)
      base.extend ClassMethods
    end
  end
end<commit_msg>Move attributes accessor to attributes module<commit_after>require "resourced/version"
require "resourced/attributes"
require "resourced/finders"

module Resourced
  module Resource
    module InstanceMethods
      def initialize(params, scope=nil)
        @scope = scope
        @model = self.class.instance_variable_get(:@model)
        @key   = self.class.instance_variable_get(:@key)
        @chain = @model
        super
      end
      attr_accessor :scope
      attr_reader   :model, :chain, :key

      ##
      # Run external code in context of resource
      #
      # Examples:
      #
      #     resource = UserResource.new(params, scope)
      #     subj = "john"
      #     resource.context do
      #       chain.where(name: subj)
      #     end
      #
      def context(&block)
        if block_given?
          @chain = self.instance_eval(&block)
        end

        self
      end
    end

    module ClassMethods
      ##
      # Set or get model class
      #
      def model(model_class=nil)
        model_class ? @model = model_class : @model
      end

      ##
      # Duplicate resource and set another model class
      #
      def [](model_class)
        klass = self.dup
        klass.instance_variable_set(:@model, model_class)
        klass
      end

      ##
      # Set primary key
      #
      def key(key_name=nil)
        key_name ? @key = key_name.to_sym : @key
      end
    end

    def self.included(base)
      base.send(:include, Resourced::Attributes)
      base.send(:include, Resourced::Finders)
      base.send(:include, InstanceMethods)
      base.extend ClassMethods
    end
  end
end
{'fraction_non_alphanumeric': 0.08842493091802273, 'fraction_numerical': 0.0, 'mean_word_length': 1.9167412712623098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1727057', 'n_tokens_mistral': 972, 'n_tokens_neox': 951, 'n_words': 229}