Class: Cyrax::Presenters::BaseCollection
- Inherits:
-
Object
- Object
- Cyrax::Presenters::BaseCollection
- Defined in:
- lib/cyrax/presenters/base_collection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
-
#initialize(collection, options = {}) ⇒ BaseCollection
constructor
A new instance of BaseCollection.
- #method_missing(method, *args, &block) ⇒ Object
- #presented_collection ⇒ Object
Constructor Details
#initialize(collection, options = {}) ⇒ BaseCollection
Returns a new instance of BaseCollection.
5 6 7 8 |
# File 'lib/cyrax/presenters/base_collection.rb', line 5 def initialize(collection, = {}) @collection = collection @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
27 28 29 30 |
# File 'lib/cyrax/presenters/base_collection.rb', line 27 def method_missing(method, *args, &block) return super unless collection.respond_to?(method) collection.send(method, *args, &block) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
3 4 5 |
# File 'lib/cyrax/presenters/base_collection.rb', line 3 def collection @collection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/cyrax/presenters/base_collection.rb', line 3 def @options end |
Instance Method Details
#as_json(*args) ⇒ Object
23 24 25 |
# File 'lib/cyrax/presenters/base_collection.rb', line 23 def as_json(*args) presented_collection.as_json(*args) end |
#presented_collection ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/cyrax/presenters/base_collection.rb', line 13 def presented_collection if collection.is_a?(ActiveRecord::Relation) collection.to_a elsif collection.respond_to?(:all) collection.all.to_a else Array.wrap collection end end |