class Paraphrase::Repository
{Repository} is were query-specific scopes are defined. They can be defined by re-opening the class inside the {Query} class definition or by using the {Query.scope scope} class method on {Query}. Both methods are equivalent.
Inside scopes defined on a {Repository}, the method has access to {Query#params} as `params`.
Attributes
mapping[R]
params[R]
relation[R]
Public Class Methods
chain(relation, mapping, params)
click to toggle source
# File lib/paraphrase/repository.rb, line 11 def self.chain(relation, mapping, params) new(relation, mapping, params).chain end
new(relation, mapping, params)
click to toggle source
# File lib/paraphrase/repository.rb, line 15 def initialize(relation, mapping, params) @relation, @mapping, @params = relation, mapping, params end
Public Instance Methods
chain()
click to toggle source
# File lib/paraphrase/repository.rb, line 19 def chain if mapping.satisfied?(params) if scope.arity.zero? relation.scoping { scope.call } else values = mapping.values(params) relation.scoping { scope.call(*values) } end else relation end end
scope()
click to toggle source
# File lib/paraphrase/repository.rb, line 33 def scope @scope ||= if respond_to?(mapping.name) method(mapping.name) else relation.klass.method(mapping.name) end end