Class: FogTracker::Query::QueryProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/fog_tracker/query/query_processor.rb

Overview

A class for filtering the Fog resources for a set of AccountTrackers, based on a regular-expression-based query

Constant Summary collapse

QUERY_PATTERN =

The Regular Expression which all resource queries must match

%r{(.*)::(.*)::(.*)::(.*)}

Instance Method Summary collapse

Constructor Details

#initialize(trackers, options = {}) ⇒ QueryProcessor

Creates an object for filtering Resources from a set of AccountTrackers

Parameters:

  • trackers (Hash)

    a Hash of AccountTrackers, indexed by account name

  • options (Hash) (defaults to: {})

    optional additional parameters:

    • :logger - a Ruby Logger-compatible object



14
15
16
17
# File 'lib/fog_tracker/query/query_processor.rb', line 14

def initialize(trackers, options={})
  @trackers = trackers
  @log      = options[:logger] || FogTracker.default_logger
end

Instance Method Details

#execute(query) ⇒ Array <Fog::Model>

Uses the query string to filter all polled resources for a desired subset

Parameters:

  • query (String)

    a string used to filter for matching resources

Returns:

  • (Array <Fog::Model>)

    an Array of Resources, filtered by query



23
24
25
26
27
28
29
30
31
32
# File 'lib/fog_tracker/query/query_processor.rb', line 23

def execute(query)
  acct_pattern, svc_pattern, prov_pattern, col_pattern = parse_query(query)
  filter_by_collection(
    filter_by_provider(
      filter_by_service(
        attach_query_methods((acct_pattern)),
        svc_pattern),
      prov_pattern),
    col_pattern)
end