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.
7 8 9 10 11 12 |
# File 'lib/queryable_collection/worker.rb', line 7 def initialize(elements, queryable_attributes) @elements = Array(elements) fail(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
14 15 16 |
# File 'lib/queryable_collection/worker.rb', line 14 def all @elements end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/queryable_collection/worker.rb', line 30 def empty? @elements.empty? end |
#find_by(query) ⇒ Object
26 27 28 |
# File 'lib/queryable_collection/worker.rb', line 26 def find_by(query) where(query).first end |
#first ⇒ Object
18 19 20 |
# File 'lib/queryable_collection/worker.rb', line 18 def first @elements.first end |
#to_a ⇒ Object
34 35 36 |
# File 'lib/queryable_collection/worker.rb', line 34 def to_a @elements.dup end |
#where(query) ⇒ Object
22 23 24 |
# File 'lib/queryable_collection/worker.rb', line 22 def where(query) self.class.new(select(query), @queryable_attributes) end |