Class: Nanite::LocalState
Instance Method Summary collapse
-
#initialize(hsh = {}) ⇒ LocalState
constructor
A new instance of LocalState.
- #nanites_for(request) ⇒ Object
- #update_status(name, status) ⇒ Object
- #update_tags(name, new_tags, obsolete_tags) ⇒ 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
#nanites_for(request) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nanite/local_state.rb', line 9 def nanites_for(request) = request. service = request.type if service nanites = reject { |_, state| !state[:services].include?(service) } else nanites = self end if .nil? || .empty? service ? nanites : {} else nanites.reject { |_, state| (state[:tags] & ).empty? } end end |
#update_status(name, status) ⇒ Object
25 26 27 |
# File 'lib/nanite/local_state.rb', line 25 def update_status(name, status) self[name].update(:status => status, :timestamp => Time.now.utc.to_i) end |
#update_tags(name, new_tags, obsolete_tags) ⇒ Object
29 30 31 32 33 |
# File 'lib/nanite/local_state.rb', line 29 def (name, , ) = self[name] && self[name][:tags] = ( || []) + ( || []) - ( || []) self[name].update(:tags => .uniq) end |