Class: Fixably::ResourceLazyLoader
- Inherits:
-
Object
- Object
- Fixably::ResourceLazyLoader
- Defined in:
- lib/fixably/resource_lazy_loader.rb
Instance Attribute Summary collapse
-
#associations_to_expand ⇒ Object
readonly
Returns the value of attribute associations_to_expand.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #all(*args) ⇒ Object
- #find(*args) ⇒ Object
- #first(*args) ⇒ Object
- #includes(association) ⇒ Object
-
#initialize(model:) ⇒ ResourceLazyLoader
constructor
A new instance of ResourceLazyLoader.
- #last(*args) ⇒ Object
- #where(clauses = {}) ⇒ Object
Constructor Details
#initialize(model:) ⇒ ResourceLazyLoader
Returns a new instance of ResourceLazyLoader.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fixably/resource_lazy_loader.rb', line 8 def initialize(model:) if !model.respond_to?(:ancestors) || !model.ancestors.include?(ApplicationResource) raise( ArgumentError, "The model is expected to be a class that extend ApplicationResource" ) end @model = model @associations_to_expand = Set.new end |
Instance Attribute Details
#associations_to_expand ⇒ Object (readonly)
Returns the value of attribute associations_to_expand.
6 7 8 |
# File 'lib/fixably/resource_lazy_loader.rb', line 6 def @associations_to_expand end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/fixably/resource_lazy_loader.rb', line 5 def model @model end |
Instance Method Details
#all(*args) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/fixably/resource_lazy_loader.rb', line 56 def all(*args) = (args.slice(0) || {}) arguments = [].concat(args[1..] || []) model.all(*arguments) end |
#find(*args) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/fixably/resource_lazy_loader.rb', line 34 def find(*args) id = args.slice(0) = (args.slice(1) || {}) arguments = [].concat(args[2..] || []) model.find(id, *arguments) end |
#first(*args) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/fixably/resource_lazy_loader.rb', line 42 def first(*args) = (args.slice(0) || {}) arguments = [].concat(args[1..] || []) model.first(*arguments) end |
#includes(association) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fixably/resource_lazy_loader.rb', line 21 def includes(association) unless model.reflections.key?(association) raise( ArgumentError, "#{association} is not a known association of #{model}" ) end << association self end |
#last(*args) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/fixably/resource_lazy_loader.rb', line 49 def last(*args) = (args.slice(0) || {}) arguments = [].concat(args[1..] || []) model.last(*arguments) end |
#where(clauses = {}) ⇒ Object
63 64 65 66 |
# File 'lib/fixably/resource_lazy_loader.rb', line 63 def where(clauses = {}) arguments = (clauses) model.where(arguments) end |