Class: Nanite::LocalState

Inherits:
Hash
  • Object
show all
Defined in:
lib/nanite/local_state.rb

Instance Method Summary collapse

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_servicesObject



9
10
11
# File 'lib/nanite/local_state.rb', line 9

def all_services
  all(:services)
end

#all_tagsObject



13
14
15
# File 'lib/nanite/local_state.rb', line 13

def all_tags
  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, *tags)
  tags = tags.dup.flatten
  nanites = select { |name, state| state[:services].include?(service) }
  unless tags.empty?
    nanites.select { |a, b| !(b[:tags] & 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