Module: FogTracker::Extensions::FogModel

Included in:
Fog::Model
Defined in:
lib/fog_tracker/extensions/fog_model.rb

Overview

Adds convenience methods to Fog::Model instances for gathering information about its account, and about other Fog::Model resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_fog_collection_trackerObject

a FogTracker::CollectionTracker - *do not modify* - used for #tracker_account



8
9
10
# File 'lib/fog_tracker/extensions/fog_model.rb', line 8

def _fog_collection_tracker
  @_fog_collection_tracker
end

#_query_processorObject

a FogTracker::QueryParser - *do not modify* - used for tracker_query



11
12
13
# File 'lib/fog_tracker/extensions/fog_model.rb', line 11

def _query_processor
  @_query_processor
end

Instance Method Details

#account_resources(collection_name) ⇒ Array <Fog::Model>

Returns Fog::Model resources from this Resource’s account only.

Parameters:

  • collection_name (String)

    a String which is converted to a RegEx, and used to match collection names for resources in the same account as the current resource.

Returns:

  • (Array <Fog::Model>)

    an Array of resources from this Model’s accout, whose collection matches collection_name.



27
28
29
30
31
32
33
34
35
36
# File 'lib/fog_tracker/extensions/fog_model.rb', line 27

def (collection_name)
  results = Array.new
  if @_query_processor
    results = @_query_processor.execute(
      "#{[:name]}::*::*::#{collection_name}"
    )
    (results.each {|r| yield r}) if block_given?
  end
  results
end

#tracker_accountHash

Returns a cleaned copy of the resource’s account information from the its collection tracker (credentials are removed).

Returns:

  • (Hash)

    a cleaned copy of the resource’s account information



16
17
18
19
# File 'lib/fog_tracker/extensions/fog_model.rb', line 16

def 
  (not _fog_collection_tracker) ? Hash.new :
  _fog_collection_tracker.
end

#tracker_descriptionString

returns a descriptive identifier unique to this resource

Returns:

  • (String)

    the type, identity, and account name of the resource



54
55
56
57
# File 'lib/fog_tracker/extensions/fog_model.rb', line 54

def tracker_description
   type = (self.class.name.match(/::([^:]+)$/))[1]
  "#{type} #{self.identity} in account #{[:name]}"
end

#tracker_query(query_string) ⇒ Array <Fog::Model>

Runs a query across all accounts using a Query::QueryProcessor. Any code block parameter will be executed once for (and with) each resulting resource.

Parameters:

  • query (String)

    a string used to filter for matching resources

Returns:

  • (Array <Fog::Model>)

    an Array of Resources, filtered by query



43
44
45
46
47
48
49
50
# File 'lib/fog_tracker/extensions/fog_model.rb', line 43

def tracker_query(query_string)
  results = Array.new
  if @_query_processor
    results = @_query_processor.execute(query_string)
    (results.each {|r| yield r}) if block_given?
  end
  results
end