Method: SkullIsland::ResourceCollection#where
- Defined in:
- lib/skull_island/resource_collection.rb
#where(attribute, value, options = {}) ⇒ ResourceCollection Also known as: and
Horribly inefficient way to allow querying Resources by their attributes. This method can be chained for multiple / more specific queries.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/skull_island/resource_collection.rb', line 115 def where(attribute, value, = {}) valid_comparisons = %i[== != > >= < <= match] [:comparison] ||= value.is_a?(Regexp) ? :match : '==' unless valid_comparisons.include?([:comparison].to_sym) raise Exceptions::InvalidWhereQuery end self.class.new( @list.collect do |item| if item.send(attribute).nil? nil elsif item.send(attribute).send([:comparison].to_sym, value) item end end.compact, type: @type, api_client: @api_client ) end |