Class: FogTracker::CollectionTracker
- Inherits:
-
Object
- Object
- FogTracker::CollectionTracker
- Defined in:
- lib/fog_tracker/collection_tracker.rb
Overview
Tracks a single Fog collection in a single account. Each CollectionTracker instance is tightly bound to an AccountTracker.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
An Array of Fog::Model objects, all of the same resource type (class).
Instance Method Summary collapse
-
#clean_account_data ⇒ Hash
A Hash of account information, slighly modified: a :name parameter is added, and the :credentials are removed :preceeding_update_time is also added.
-
#initialize(resource_type, account_tracker) ⇒ CollectionTracker
constructor
Creates an object for tracking a single Fog collection in a single account.
-
#update ⇒ Object
Polls the AccountTracker‘s connection for updated info on all existing instances of this tracker’s resource_type.
Constructor Details
#initialize(resource_type, account_tracker) ⇒ CollectionTracker
Creates an object for tracking a single Fog collection in a single account
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog_tracker/collection_tracker.rb', line 14 def initialize(resource_type, account_tracker) @type = resource_type @account_tracker = account_tracker @account = account_tracker.account @account_name = account_tracker.name @log = account_tracker.log @collection = Array.new @log.debug "Created tracker for #{@type} on #{@account_name}." end |
Instance Attribute Details
#collection ⇒ Object (readonly)
An Array of Fog::Model objects, all of the same resource type (class)
8 9 10 |
# File 'lib/fog_tracker/collection_tracker.rb', line 8 def collection @collection end |
Instance Method Details
#clean_account_data ⇒ Hash
Returns a Hash of account information, slighly modified: a :name parameter is added, and the :credentials are removed :preceeding_update_time is also added.
44 45 46 47 48 49 50 |
# File 'lib/fog_tracker/collection_tracker.rb', line 44 def clean_account_data @clean_data ||= @account # generate this data only once per res @clean_data[:name] = @account_name @clean_data[:credentials] = Hash.new @clean_data[:preceeding_update_time] = @account_tracker.preceeding_update_time @clean_data end |
#update ⇒ Object
Polls the AccountTracker‘s connection for updated info on all existing instances of this tracker’s resource_type
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog_tracker/collection_tracker.rb', line 26 def update new_collection = Array.new fog_collection = @account_tracker.connection.send(@type) || Array.new @log.info "Fetching #{fog_collection.count} #{@type} on #{@account_name}." # Here's where most of the network overhead is actually incurred fog_collection.each do |resource| @log.debug "Fetching resource: #{resource.class} #{resource.identity}" resource._fog_collection_tracker = self new_collection << resource #@log.debug "Got resource: #{resource.inspect}" end @log.info "Fetched #{new_collection.count} #{@type} on #{@account_name}." @collection = new_collection end |