Module: Noah::SinatraTagHelpers

Defined in:
lib/noah/helpers/tag_helpers.rb

Instance Method Summary collapse

Instance Method Details

#tag(primitive, name, tags) ⇒ Object

TODO DRY this sumbitch up TODO add status in json response



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/noah/helpers/tag_helpers.rb', line 6

def tag(primitive, name, tags)
  case primitive
  when "services"
    servicename, hostname = name.split('/')
    obj = host_service(hostname, servicename)
  when "hosts"
    obj = Noah::Host.find(:name=>name).first
  when "configurations"
    obj = Noah::Configuration.find(:name=>name).first
  when "applications"
    obj = Noah::Application.find(:name=>name).first
  when "ephemerals"
    obj = Noah::Ephemeral.find(:path=>"/#{name}").first
  else
    halt 404
  end
  obj.nil? ? (halt 404) : (obj.tag!(tags))
  obj.to_json
end

#untag(primitive, name, tags) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/noah/helpers/tag_helpers.rb', line 26

def untag(primitive, name, tags)
  case primitive
  when "services"
    servicename, hostname = name.split('/')
    obj = host_service(hostname, servicename)
  when "hosts"
    obj = Noah::Host.find(:name=>name).first
  when "configurations"
    obj = Noah::Configuration.find(:name=>name).first
  when "applications"
    obj = Noah::Application.find(:name=>name).first
  when "ephemerals"
    obj = Noah::Ephemeral.find(:path=>"/#{name}").first
  else
    halt 404
  end
  obj.to_json
end