class QueryableCollection::Worker
Public Class Methods
new(elements, queryable_attributes)
click to toggle source
# 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
Public Instance Methods
all()
click to toggle source
# File lib/queryable_collection/worker.rb, line 14 def all @elements end
empty?()
click to toggle source
# File lib/queryable_collection/worker.rb, line 30 def empty? @elements.empty? end
find_by(query)
click to toggle source
# File lib/queryable_collection/worker.rb, line 26 def find_by(query) where(query).first end
first()
click to toggle source
# File lib/queryable_collection/worker.rb, line 18 def first @elements.first end
to_a()
click to toggle source
# File lib/queryable_collection/worker.rb, line 34 def to_a @elements.dup end
where(query)
click to toggle source
# File lib/queryable_collection/worker.rb, line 22 def where(query) self.class.new(select(query), @queryable_attributes) end
Private Instance Methods
select(query)
click to toggle source
# File lib/queryable_collection/worker.rb, line 44 def select(query) Query.new(query, @queryable_attributes).perform(@elements) end
valid_queryable_attributes?(queryable_attributes)
click to toggle source
# File lib/queryable_collection/worker.rb, line 40 def valid_queryable_attributes?(queryable_attributes) queryable_attributes.is_a?(Enumerable) && !queryable_attributes.empty? end