Class: Paraphrase::Repository
- Inherits:
-
Object
- Object
- Paraphrase::Repository
- Defined in:
- lib/paraphrase/repository.rb
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Class Method Summary collapse
Instance Method Summary collapse
- #chain ⇒ Object
-
#initialize(relation, mapping, params) ⇒ Repository
constructor
A new instance of Repository.
- #scope ⇒ Object
Constructor Details
#initialize(relation, mapping, params) ⇒ Repository
Returns a new instance of Repository.
9 10 11 |
# File 'lib/paraphrase/repository.rb', line 9 def initialize(relation, mapping, params) @relation, @mapping, @params = relation, mapping, params end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
3 4 5 |
# File 'lib/paraphrase/repository.rb', line 3 def mapping @mapping end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/paraphrase/repository.rb', line 3 def params @params end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
3 4 5 |
# File 'lib/paraphrase/repository.rb', line 3 def relation @relation end |
Class Method Details
.chain(relation, mapping, params) ⇒ Object
5 6 7 |
# File 'lib/paraphrase/repository.rb', line 5 def self.chain(relation, mapping, params) new(relation, mapping, params).chain end |
Instance Method Details
#chain ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/paraphrase/repository.rb', line 13 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 ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/paraphrase/repository.rb', line 27 def scope @scope ||= if respond_to?(mapping.name) method(mapping.name) else relation.klass.method(mapping.name) end end |