<commit_before>require 'blockenspiel'
require 'toast/config_dsl'

module Toast
  module ActiveRecordExtensions

    # Configuration DSL
    def acts_as_resource &block

      @toast_configs ||= Array.new

      @toast_configs << Toast::ConfigDSL::Base.new(self)

      Blockenspiel.invoke( block, @toast_configs.last)

      # add class methods
      self.instance_eval do

        def is_resourceful_model?
          true
        end

        def toast_configs
          @toast_configs
        end

        # get a config by media type or first one if none matches
        def toast_config media_type
          @toast_configs.find do |tc|
            tc.media_type == media_type || tc.in_collection.media_type == media_type
          end || @toast_configs.first
        end
      end

      # add instance methods
      self.class_eval do
        # Return the path segment of the URI of this record
        def uri_path
          "/" +
            self.class.to_s.pluralize.underscore + "/" +
            self.id.to_s
        end

        # Like ActiveRecord::Base.attributes, but result Hash includes
        # only attributes from the list _attr_names_ plus the
        # associations _assoc_names_ as links and the 'self' link
        def represent attr_names, assoc_names, base_uri, media_type
          props = {}

          attr_names.each do |name|
            unless self.respond_to?(name) && self.method(name).arity == 0
              raise "Toast Error: Connot find instance method '#{self.class}##{name}' of arity 0"
            end
            props[name] = self.send(name)
          end

          assoc_names.each do |name|
            props[name] = "#{base_uri}#{self.uri_path}/#{name}"
          end

          props["self"] = base_uri + self.uri_path

          props
        end
      end
    end

    # defaults for non resourceful-models
    def is_resourceful_model?
      false
    end
    def resourceful_model_options
      nil
    end<commit_msg>arity cannot be checked sometimes<commit_after>require 'blockenspiel'
require 'toast/config_dsl'

module Toast
  module ActiveRecordExtensions

    # Configuration DSL
    def acts_as_resource &block

      @toast_configs ||= Array.new

      @toast_configs << Toast::ConfigDSL::Base.new(self)

      Blockenspiel.invoke( block, @toast_configs.last)

      # add class methods
      self.instance_eval do

        def is_resourceful_model?
          true
        end

        def toast_configs
          @toast_configs
        end

        # get a config by media type or first one if none matches
        def toast_config media_type
          @toast_configs.find do |tc|
            tc.media_type == media_type || tc.in_collection.media_type == media_type
          end || @toast_configs.first
        end
      end

      # add instance methods
      self.class_eval do
        # Return the path segment of the URI of this record
        def uri_path
          "/" +
            self.class.to_s.pluralize.underscore + "/" +
            self.id.to_s
        end

        # Like ActiveRecord::Base.attributes, but result Hash includes
        # only attributes from the list _attr_names_ plus the
        # associations _assoc_names_ as links and the 'self' link
        def represent attr_names, assoc_names, base_uri, media_type
          props = {}

          attr_names.each do |name|
            unless self.respond_to?(name)
              raise "Toast Error: Connot find instance method '#{self.class}##{name}'"
            end
            props[name] = self.send(name)
          end

          assoc_names.each do |name|
            props[name] = "#{base_uri}#{self.uri_path}/#{name}"
          end

          props["self"] = base_uri + self.uri_path

          props
        end
      end
    end

    # defaults for non resourceful-models
    def is_resourceful_model?
      false
    end
    def resourceful_model_options
      nil
    end
{'fraction_non_alphanumeric': 0.07396072430502423, 'fraction_numerical': 0.000510073960724305, 'mean_word_length': 1.9444444444444444, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5509852', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1124, 'n_words': 309}