<commit_before>require 'forwardable'
require 'active_support/all'
require 'active_model'

module JsonApiClient
  class Resource
    extend ActiveModel::Naming
    extend ActiveModel::Translation
    include ActiveModel::Validations
    include ActiveModel::Conversion
    include ActiveModel::Serialization

    include Helpers::DynamicAttributes
    include Helpers::Dirty

    attr_accessor :last_result_set,
                  :links,
                  :relationships
    class_attribute :site,
                    :primary_key,
                    :parser,
                    :paginator,
                    :connection_class,
                    :connection_object,
                    :connection_options,
                    :query_builder,
                    :linker,
                    :relationship_linker,
                    :read_only_attributes,
                    :requestor_class,
                    :associations,
                    instance_accessor: false
    self.primary_key          = :id
    self.parser               = Parsers::Parser
    self.paginator            = Paginating::Paginator
    self.connection_class     = Connection
    self.connection_options   = {}
    self.query_builder        = Query::Builder
    self.linker               = Linking::Links
    self.relationship_linker  = Relationships::Relations
    self.read_only_attributes = [:id, :type, :links, :meta, :relationships]
    self.requestor_class      = Query::Requestor
    self.associations         = []

    include Associations::BelongsTo
    include Associations::HasMany
    include Associations::HasOne

    class << self
      extend Forwardable
      def_delegators :_new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :with_params, :first, :find

      # The table name for this resource. i.e. Article -> articles, Person -> people
      #
      # @return [String] The table name for this resource
      def table_name
        resource_name.pluralize
      end

      # The name of a single resource. i.e. Article -> article, Person -> person
      #
      # @return [String]
      def resource_name
        name.demodulize.underscore
      end

      # Specifies the JSON API resource type. By default this is inferred
      # from the resource class name.
      #
      # @return [String] Resource path
      def type
        table_name
      end

      # Specifies the relative path that should be used for this resource;
      # by default, this is inferred from the resource class name.
      #
      # @return [String] Resource path
      def resource_path
        table_name
      end

      # Load a resource object from attributes and consider it persisted
      #
      # @return [Resource] Persisted resource object
      def load(params)
        new(params).tap do |resource|
          resource.mark_as_persisted!
          resource.clear_changes_information
        end
      end

      # Return/build a connection object
      #
      # @return [Connection] The connection to the json api server
      def connection(rebuild = false, &block)
        _build_connection(rebuild, &block)
        connection_object
      end

      # Param names that will be considered path params. They will be used
      # to build the resource path rather than treated as attributes
      #
      # @return [Array] Param name symbols of parameters that will be treated as path parameters
      def prefix_params
        _belongs_to_associations.map(&:param)
      end

      # Return the path or path pattern for this resource
      def path(params = nil)
        parts = [resource_path]
        if params
          path_params = params.delete(:path) || params
          parts.unshift(_prefix_path % path_params.symbolize_keys)
        else
          parts.unshift(_prefix_path)
        end
        parts.reject!(&:blank?)
        File.join(*parts)
      rescue KeyError
        raise ArgumentError, "Not all prefix parameters specified"
      end

      # Create a new instance of this resource class
      #
      # @param attributes [Hash] The attributes to create this resource with
      # @return [Resource] The instance you tried to create. You will have to check the persisted state or errors on this object to see success/failure.
      def create(attributes = {})
        new(attributes).tap do |resource|
          resource.save<commit_msg>Don't attempt param substitution for blank `_prefix_path`<commit_after>require 'forwardable'
require 'active_support/all'
require 'active_model'

module JsonApiClient
  class Resource
    extend ActiveModel::Naming
    extend ActiveModel::Translation
    include ActiveModel::Validations
    include ActiveModel::Conversion
    include ActiveModel::Serialization

    include Helpers::DynamicAttributes
    include Helpers::Dirty

    attr_accessor :last_result_set,
                  :links,
                  :relationships
    class_attribute :site,
                    :primary_key,
                    :parser,
                    :paginator,
                    :connection_class,
                    :connection_object,
                    :connection_options,
                    :query_builder,
                    :linker,
                    :relationship_linker,
                    :read_only_attributes,
                    :requestor_class,
                    :associations,
                    instance_accessor: false
    self.primary_key          = :id
    self.parser               = Parsers::Parser
    self.paginator            = Paginating::Paginator
    self.connection_class     = Connection
    self.connection_options   = {}
    self.query_builder        = Query::Builder
    self.linker               = Linking::Links
    self.relationship_linker  = Relationships::Relations
    self.read_only_attributes = [:id, :type, :links, :meta, :relationships]
    self.requestor_class      = Query::Requestor
    self.associations         = []

    include Associations::BelongsTo
    include Associations::HasMany
    include Associations::HasOne

    class << self
      extend Forwardable
      def_delegators :_new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :with_params, :first, :find

      # The table name for this resource. i.e. Article -> articles, Person -> people
      #
      # @return [String] The table name for this resource
      def table_name
        resource_name.pluralize
      end

      # The name of a single resource. i.e. Article -> article, Person -> person
      #
      # @return [String]
      def resource_name
        name.demodulize.underscore
      end

      # Specifies the JSON API resource type. By default this is inferred
      # from the resource class name.
      #
      # @return [String] Resource path
      def type
        table_name
      end

      # Specifies the relative path that should be used for this resource;
      # by default, this is inferred from the resource class name.
      #
      # @return [String] Resource path
      def resource_path
        table_name
      end

      # Load a resource object from attributes and consider it persisted
      #
      # @return [Resource] Persisted resource object
      def load(params)
        new(params).tap do |resource|
          resource.mark_as_persisted!
          resource.clear_changes_information
        end
      end

      # Return/build a connection object
      #
      # @return [Connection] The connection to the json api server
      def connection(rebuild = false, &block)
        _build_connection(rebuild, &block)
        connection_object
      end

      # Param names that will be considered path params. They will be used
      # to build the resource path rather than treated as attributes
      #
      # @return [Array] Param name symbols of parameters that will be treated as path parameters
      def prefix_params
        _belongs_to_associations.map(&:param)
      end

      # Return the path or path pattern for this resource
      def path(params = nil)
        parts = [resource_path]
        if params && _prefix_path.present?
          path_params = params.delete(:path) || params
          parts.unshift(_prefix_path % path_params.symbolize_keys)
        else
          parts.unshift(_prefix_path)
        end
        parts.reject!(&:blank?)
        File.join(*parts)
      rescue KeyError
        raise ArgumentError, "Not all prefix parameters specified"
      end

      # Create a new instance of this resource class
      #
      # @param attributes [Hash] The attributes to create this resource with
      # @return [Resource] The instance you tried to create. You will have to check the persisted state or errors on this object to see success/failure.
      def create(attributes = {})
        new(attributes).tap do |resource|
          resource.save
{'fraction_non_alphanumeric': 0.06650050979947887, 'fraction_numerical': 0.0, 'mean_word_length': 2.0888733379986, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2739424', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2184, 'n_words': 710}