Class: Roles
- Inherits:
-
Application
- Object
- Merb::Controller
- Application
- Roles
- Defined in:
- app/controllers/roles.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /roles.
-
#destroy ⇒ Object
DELETE /roles/:id.
-
#environment ⇒ Object
GET /roles/:id/environments/:env_id.
-
#environments ⇒ Object
GET /roles/:id/environments.
-
#index ⇒ Object
GET /roles.
-
#show ⇒ Object
GET /roles/:id.
-
#update ⇒ Object
PUT /roles/:id.
Methods inherited from Application
#access_denied, #admin_or_requesting_node, #authenticate_every, #display, #get_available_recipes, #is_admin, #is_admin_or_validator, #redirect_back_or_default, #store_location
Instance Method Details
#create ⇒ Object
POST /roles
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/roles.rb', line 27 def create @role = params["inflated_object"] exists = true begin Chef::Role.cdb_load(@role.name) rescue Chef::Exceptions::CouchDBNotFound exists = false end raise Conflict, "Role already exists" if exists @role.cdb_save self.status = 201 display({ :uri => absolute_url(:role, :id => @role.name) }) end |
#destroy ⇒ Object
DELETE /roles/:id
59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/roles.rb', line 59 def destroy begin @role = Chef::Role.cdb_load(params[:id]) rescue Chef::Exceptions::CouchDBNotFound => e raise NotFound, "Cannot load role #{params[:id]}" end @role.cdb_destroy display @role end |
#environment ⇒ Object
GET /roles/:id/environments/:env_id
70 71 72 73 74 75 76 77 |
# File 'app/controllers/roles.rb', line 70 def environment begin @role = Chef::Role.cdb_load(params[:role_id]) rescue Chef::Exceptions::CouchDBNotFound => e raise NotFound, "Cannot load role #{params[:role_id]}" end display("run_list" => @role.env_run_lists[params[:env_id]]) end |
#environments ⇒ Object
GET /roles/:id/environments
80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/roles.rb', line 80 def environments begin @role = Chef::Role.cdb_load(params[:role_id]) rescue Chef::Exceptions::CouchDBNotFound => e raise NotFound, "Cannot load role #{params[:role_id]}" end display(@role.env_run_lists.keys.sort) end |
#index ⇒ Object
GET /roles
10 11 12 13 |
# File 'app/controllers/roles.rb', line 10 def index @role_list = Chef::Role.cdb_list(true) display(@role_list.inject({}) { |r,role| r[role.name] = absolute_url(:role, role.name); r }) end |
#show ⇒ Object
GET /roles/:id
16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/roles.rb', line 16 def show begin @role = Chef::Role.cdb_load(params[:id]) rescue Chef::Exceptions::CouchDBNotFound => e raise NotFound, "Cannot load role #{params[:id]}" end @role.couchdb_rev = nil display @role end |
#update ⇒ Object
PUT /roles/:id
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/roles.rb', line 44 def update begin @role = Chef::Role.cdb_load(params[:id]) rescue Chef::Exceptions::CouchDBNotFound => e raise NotFound, "Cannot load role #{params[:id]}" end @role.update_from!(params["inflated_object"]) @role.cdb_save self.status = 200 @role.couchdb_rev = nil display(@role) end |