<commit_before>module Rapidash
  module Resourceable
    def self.included(base)
      base.extend ClassMethods
    end

    def resource(name, id = nil, options = {})
      options[:url] ||= name
      if self.respond_to?(:url)
        options = {:previous_url => self.url}.merge!(options)
      end
      client = self
      client = self.client if self.respond_to?(:client)
      Rapidash::Base.new(client, id, options)
    end

    def resource!(*args)
      self.resource(*args).call!
    end


    module ClassMethods
      def resource(*names)
        options = names.extract_options!

        mod = self.to_s.split("::")[0...-1]
        mod = mod.empty? ? Object : mod.join("::").constantize

        names.each do |name|
          if options[:class_name]
            class_name = options[:class_name].to_s
          else
            class_name = name.to_s.camelcase.singularize

            unless mod == Object
              class_name = "#{mod}::#{class_name}"
            end
          end

          begin
            klass = class_name.constantize
          rescue NameError
            Kernel.warn "[DEPRECATED] - RAPIDASH WARNING using #{class_name.pluralize} instead of #{class_name.singularize} - please either use `#{class_name.singularize}` or set the class name with `resource #{name}, :class_name => #{class_name.pluralize}` implicit plural naming will be deprecated in Rapidash 1.0"
            klass = class_name.pluralize.constantize
          end

          define_method(name) do |*args|
            if self.respond_to?(:url)
              options = {:previous_url => self.url}
              if args[args.length - 1].is_a?(Hash)
                args[args.length - 1].merge!(options)
              else
                args << options
              end
            end
            client = self
            client = self.client if self.respond_to?(:client)
            klass.new(client, *args)
          end

          define_method("#{name}!".to_sym) do |*args|
            self.send(name, *args).call!
          end
        end
      end
    end
  end
end
<commit_msg>Add collection and member methods<commit_after>module Rapidash
  module Resourceable
    def self.included(base)
      base.extend ClassMethods
    end

    def resource(name, id = nil, options = {})
      options[:url] ||= name
      if self.respond_to?(:url)
        options = {:previous_url => self.url}.merge!(options)
      end
      client = self
      client = self.client if self.respond_to?(:client)
      Rapidash::Base.new(client, id, options)
    end

    def resource!(*args)
      self.resource(*args).call!
    end


    module ClassMethods
      def resource(*names)
        options = names.extract_options!

        mod = self.to_s.split("::")[0...-1]
        mod = mod.empty? ? Object : mod.join("::").constantize

        names.each do |name|
          if options[:class_name]
            class_name = options[:class_name].to_s
          else
            class_name = name.to_s.camelcase.singularize

            unless mod == Object
              class_name = "#{mod}::#{class_name}"
            end
          end

          begin
            klass = class_name.constantize
          rescue NameError
            Kernel.warn "[DEPRECATED] - RAPIDASH WARNING using #{class_name.pluralize} instead of #{class_name.singularize} - please either use `#{class_name.singularize}` or set the class name with `resource #{name}, :class_name => #{class_name.pluralize}` implicit plural naming will be deprecated in Rapidash 1.0"
            klass = class_name.pluralize.constantize
          end

          define_method(name) do |*args|
            if self.respond_to?(:url)
              options = {:previous_url => self.url}
              if args[args.length - 1].is_a?(Hash)
                args[args.length - 1].merge!(options)
              else
                args << options
              end
            end
            client = self
            client = self.client if self.respond_to?(:client)
            klass.new(client, *args)
          end

          define_method("#{name}!".to_sym) do |*args|
            self.send(name, *args).call!
          end
        end
      end

      def collection(name, options = {})
        path = options[:path] || name.to_s
        path.gsub!(/^\//, '')

        method = options[:method] || :get

        define_method("#{name}!") do
          @url += "/#{path}"
          @options[:method] = method
          call!
        end
      end

      def member(name, options = {})
        path = options[:path] || name.to_s
        path.gsub!(/^\//, '')

        method = options[:method] || :get

        define_method("#{name}!") do |id|
          @url += "/#{id}/#{path}"
          @options[:method] = method
          call!
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1199418966590579, 'fraction_numerical': 0.0024901431832330357, 'mean_word_length': 1.8104956268221575, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 9, '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': '7530074', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1389, 'n_words': 329}