Class: Nanite::LocalState
Instance Method Summary collapse
- #all_services ⇒ Object
- #all_tags ⇒ Object
-
#initialize(hsh = {}) ⇒ LocalState
constructor
A new instance of LocalState.
- #nanites_for(service, *tags) ⇒ Object
- #update_status(name, status) ⇒ Object
Constructor Details
#initialize(hsh = {}) ⇒ LocalState
Returns a new instance of LocalState.
3 4 5 6 7 |
# File 'lib/nanite/local_state.rb', line 3 def initialize(hsh={}) hsh.each do |k,v| self[k] = v end end |
Instance Method Details
#all_services ⇒ Object
9 10 11 |
# File 'lib/nanite/local_state.rb', line 9 def all_services all(:services) end |
#all_tags ⇒ Object
13 14 15 |
# File 'lib/nanite/local_state.rb', line 13 def all(:tags) end |
#nanites_for(service, *tags) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/nanite/local_state.rb', line 17 def nanites_for(service, *) = .dup.flatten nanites = select { |name, state| state[:services].include?(service) } unless .empty? nanites.select { |a, b| !(b[:tags] & ).empty? } else nanites end.to_a end |
#update_status(name, status) ⇒ Object
27 28 29 |
# File 'lib/nanite/local_state.rb', line 27 def update_status(name, status) self[name].update(:status => status, :timestamp => Time.now.utc.to_i) end |