Class: EndecaOnDemand::Collection
- Defined in:
- lib/endeca_on_demand/collection.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Attributes inherited from Proxy
Instance Method Summary collapse
-
#class ⇒ Object
override proxy ##.
-
#initialize(klass, target, mapping = nil) ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ Object
- #where(conditions = {}) ⇒ Object
Constructor Details
#initialize(klass, target, mapping = nil) ⇒ Collection
Returns a new instance of Collection.
6 7 8 9 10 |
# File 'lib/endeca_on_demand/collection.rb', line 6 def initialize(klass, target, mapping = nil) @klass, @target = klass, target @target = target.map { |object| @klass.new(mapping, object) } if mapping.present? extend klass.collection_class if klass.respond_to?(:collection_class) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
38 39 40 |
# File 'lib/endeca_on_demand/collection.rb', line 38 def method_missing(name, *args, &block) target.send(name, *args, &block) end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/endeca_on_demand/collection.rb', line 4 def klass @klass end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/endeca_on_demand/collection.rb', line 4 def target @target end |
Instance Method Details
#class ⇒ Object
override proxy ##
14 15 16 |
# File 'lib/endeca_on_demand/collection.rb', line 14 def class EndecaOnDemand::Collection end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/endeca_on_demand/collection.rb', line 18 def inspect target.to_a.inspect end |
#where(conditions = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/endeca_on_demand/collection.rb', line 24 def where(conditions = {}) target.select do |object| conditions.all? do |key,value| value.is_a?(Regexp) ? object.send(key) =~ value : object.send(key) == value end end end |