Class: QueryableCollection::Worker
- Inherits:
-
Object
- Object
- QueryableCollection::Worker
- Includes:
- Adamantium
- Defined in:
- lib/queryable_collection/worker.rb
Defined Under Namespace
Classes: Query
Instance Method Summary collapse
- #all ⇒ Object
- #empty? ⇒ Boolean
- #find_by(query) ⇒ Object
- #first ⇒ Object
-
#initialize(elements, queryable_attributes) ⇒ Worker
constructor
A new instance of Worker.
- #to_a ⇒ Object
- #where(query) ⇒ Object
Constructor Details
#initialize(elements, queryable_attributes) ⇒ Worker
Returns a new instance of Worker.
9 10 11 12 13 14 15 |
# File 'lib/queryable_collection/worker.rb', line 9 def initialize(elements, queryable_attributes) @elements = Array(elements) raise(Error, 'Queryable attributes must be a non empty list of attributes') unless valid_queryable_attributes? queryable_attributes @queryable_attributes = queryable_attributes.map(&:to_s) end |
Instance Method Details
#all ⇒ Object
17 18 19 |
# File 'lib/queryable_collection/worker.rb', line 17 def all @elements end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/queryable_collection/worker.rb', line 33 def empty? @elements.empty? end |
#find_by(query) ⇒ Object
29 30 31 |
# File 'lib/queryable_collection/worker.rb', line 29 def find_by(query) where(query).first end |
#first ⇒ Object
21 22 23 |
# File 'lib/queryable_collection/worker.rb', line 21 def first @elements.first end |
#to_a ⇒ Object
37 38 39 |
# File 'lib/queryable_collection/worker.rb', line 37 def to_a @elements.dup end |
#where(query) ⇒ Object
25 26 27 |
# File 'lib/queryable_collection/worker.rb', line 25 def where(query) self.class.new(select(query), @queryable_attributes) end |