noah 0.4 → 0.6.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Rakefile +2 -69
  2. data/lib/noah/agent.rb +1 -0
  3. data/lib/noah/agents/base_agent.rb +4 -2
  4. data/lib/noah/agents/http_agent.rb +1 -1
  5. data/lib/noah/agents/https_agent.rb +6 -0
  6. data/lib/noah/app.rb +8 -6
  7. data/lib/noah/exceptions.rb +0 -0
  8. data/lib/noah/linkable.rb +21 -0
  9. data/lib/noah/models/applications.rb +19 -9
  10. data/lib/noah/models/configurations.rb +32 -13
  11. data/lib/noah/models/ephemerals.rb +7 -6
  12. data/lib/noah/models/hosts.rb +11 -5
  13. data/lib/noah/models/link.rb +70 -29
  14. data/lib/noah/models/services.rb +11 -2
  15. data/lib/noah/models/tags.rb +86 -5
  16. data/lib/noah/models/watchers.rb +0 -1
  17. data/lib/noah/models.rb +14 -25
  18. data/lib/noah/{application_routes.rb → routes/applications.rb} +31 -27
  19. data/lib/noah/routes/configurations.rb +77 -0
  20. data/lib/noah/{ephemeral_routes.rb → routes/ephemerals.rb} +5 -5
  21. data/lib/noah/{host_routes.rb → routes/hosts.rb} +16 -1
  22. data/lib/noah/routes/links.rb +16 -0
  23. data/lib/noah/{service_routes.rb → routes/services.rb} +28 -12
  24. data/lib/noah/routes/tags.rb +15 -0
  25. data/lib/noah/{watcher_routes.rb → routes/watchers.rb} +0 -0
  26. data/lib/noah/taggable.rb +30 -0
  27. data/lib/noah/version.rb +1 -1
  28. data/lib/noah.rb +1 -0
  29. data/noah.gemspec +5 -4
  30. data/spec/application_spec.rb +3 -3
  31. data/spec/configuration_spec.rb +19 -12
  32. data/spec/host_spec.rb +5 -5
  33. data/spec/noahapp_application_spec.rb +11 -13
  34. data/spec/noahapp_configuration_spec.rb +63 -40
  35. data/spec/noahapp_ephemeral_spec.rb +15 -15
  36. data/spec/noahapp_host_spec.rb +4 -6
  37. data/spec/noahapp_service_spec.rb +8 -7
  38. data/spec/service_spec.rb +2 -2
  39. data/spec/spec_helper.rb +5 -5
  40. data/spec/support/sample_data.rb +87 -0
  41. data/spec/tag_spec.rb +78 -0
  42. data/views/index.haml +7 -1
  43. metadata +23 -16
  44. data/lib/noah/configuration_routes.rb +0 -81
  45. data/lib/noah/models/link_member.rb +0 -18
@@ -1,81 +0,0 @@
1
- class Noah::App
2
- content_type_mapping = {
3
- :yaml => "text/x-yaml",
4
- :json => "application/json",
5
- :xml => "text/xml",
6
- :string => "text/plain"
7
- }
8
- # Configuration URIs
9
- get '/configurations/:appname/:element/?' do |appname, element|
10
- a = Noah::Application.find(:name => appname).first
11
- if a.nil?
12
- halt 404
13
- else
14
- c = Noah::Configuration.find(:name => element, :application_id => a.id).first
15
- content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym]
16
- c.body
17
- end
18
- end
19
-
20
- get '/configurations/:appname/?' do |appname|
21
- config = []
22
- a = Noah::Application.find(:name => appname).first
23
- if a.nil?
24
- halt 404
25
- else
26
- Noah::Configuration.find(:application_id => a.id).sort.each {|c| config << c.to_hash}
27
- config.to_json
28
- end
29
- end
30
-
31
- get '/configurations/?' do
32
- configs = []
33
- Noah::Configuration.all.sort.each {|c| configs << c.to_hash}
34
- if configs.empty?
35
- halt 404
36
- else
37
- configs.to_json
38
- end
39
- end
40
-
41
- put '/configurations/:configname/watch' do |configname|
42
- required_params = ["endpoint"]
43
- data = JSON.parse(request.body.read)
44
- (data.keys.sort == required_params.sort) ? (c = Noah::Configuration.find(:name => configname).first) : (raise "Missing Parameters")
45
- c.nil? ? (halt 404) : (w = c.watch!(:endpoint => data['endpoint']))
46
- w.to_json
47
- end
48
-
49
- put '/configurations/:appname/:element?' do |appname, element|
50
- app = Noah::Application.find_or_create(:name => appname)
51
- config = Noah::Configuration.find_or_create(:name => element, :application_id => app.id)
52
- required_params = ["format", "body"]
53
- data = JSON.parse(request.body.read)
54
- data.keys.sort == required_params.sort ? (config.format = data["format"]; config.body = data["body"]) : (raise "Missing Parameters")
55
- if config.valid?
56
- config.save
57
- action = config.is_new? ? "create" : "update"
58
- dependency_action = app.is_new? ? "created" : "updated"
59
- r = {"result" => "success","id" => "#{config.id}", "action" => action, "dependencies" => dependency_action, "application" => app.name, "item" => config.name}
60
- r.to_json
61
- else
62
- raise "#{format_errors(config)}"
63
- end
64
- end
65
-
66
- delete '/configurations/:appname/:element?' do |appname, element|
67
- app = Noah::Application.find(:name => appname).first
68
- if app
69
- config = Noah::Configuration.find(:name=> element, :application_id => app.id).first
70
- if config
71
- config.delete
72
- r = {"result" => "success", "id" => "#{config.id}", "action" => "delete", "application" => "#{app.name}", "item" => "#{element}"}
73
- r.to_json
74
- else
75
- halt 404
76
- end
77
- else
78
- halt 404
79
- end
80
- end
81
- end
@@ -1,18 +0,0 @@
1
- module Noah
2
- class LinkMember
3
-
4
- class <<self
5
- def create(path)
6
- path_to_instance(path)
7
- end
8
-
9
- protected
10
- def path_to_instance(path)
11
- p = path.split('/')
12
- model, name = p[1], p[2]
13
- x = instance_eval(Noah::PATH_MAPPING[model])
14
- x.find(:name => name).first
15
- end
16
- end
17
- end
18
- end