Sha256: 0f36d5bb70bff76f8cced0bb72dce8d8e1d7d40530e3ad1bb17373a86c7b7e0d

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

require "where_lower/scope_spawner"

module WhereLower
  # Table name and column name seperator
  # This should never change
  SEPERATOR = ".".freeze

  # Raised when some deeply nested hash passed in which cannot be handled by this gem
  class TooDeepNestedConditions < ArgumentError; end

  # Internal API to be called from extension methods
  module Base
    class << self
      # Spawn a new scope based on existing scope and hash
      # This is method is for internal use
      #
      # @api private
      #
      # @params scope [ActiveRecord::Relation, ActiveRecord::Base]
      #   the existing scope, ActiveRecord::Base also works since `where` will be delegated
      # @params fields [Hash]
      #   @see `.where_lower`
      #
      # @see `.spawn_lower_scope_by_type`
      #
      # @return [ActiveRecord::Relation]
      def spawn_lower_scope(scope, fields)
        fields.inject(scope) do |new_scope, (name, value)|
          spawn_lower_scope_by_type(new_scope, name, value)
        end
      end

      # This is method is for internal use
      #
      # @api private
      #
      # @params scope [ActiveRecord::Relation, ActiveRecord::Base]
      #   @see spawn_lower_scope
      # @params column_or_table_name [String, Symbol]
      #   When used with nested hash, this is table name
      # @params value [Object]
      #
      # @raise [TooDeepNestedConditions] if the conditions hash has is too deep nested
      #
      # @return [ActiveRecord::Relation]
      def spawn_lower_scope_by_type(scope, column_or_table_name, value)
        ScopeSpawner.spawn(scope, column_or_table_name, value)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
where_lower-0.3.5 lib/where_lower/base.rb
where_lower-0.3.4 lib/where_lower/base.rb
where_lower-0.3.3 lib/where_lower/base.rb
where_lower-0.3.2 lib/where_lower/base.rb
where_lower-0.3.1 lib/where_lower/base.rb