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.

Parameters:

  • attribute (Symbol)

    the attribute to query

  • value (Object)

    the value to compare against

    • allowed options are “‘==’, ‘!=’, ‘>’, ‘>=’, ‘<’, ‘<=’, and ‘match’”

Returns:

Raises:



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, options = {})
  valid_comparisons = %i[== != > >= < <= match]
  options[:comparison] ||= value.is_a?(Regexp) ? :match : '=='
  unless valid_comparisons.include?(options[: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(options[:comparison].to_sym, value)
        item
      end
    end.compact,
    type: @type,
    api_client: @api_client
  )
end