Class: DataItem

Inherits:
Application show all
Defined in:
app/controllers/data_item.rb

Instance Method Summary collapse

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

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/data_item.rb', line 49

def create
  raw_data = nil
  if params.has_key?("inflated_object")
    raw_data = params["inflated_object"].raw_data
  else
    raw_data = params
    raw_data.delete(:action)
    raw_data.delete(:controller)
    raw_data.delete(:data_bag_id)
  end
  @data_bag_item = nil
  begin
    @data_bag_item = Chef::DataBagItem.cdb_load(@data_bag.name, params[:id])
  rescue Chef::Exceptions::CouchDBNotFound
    @data_bag_item = Chef::DataBagItem.new
    @data_bag_item.data_bag(@data_bag.name)
  else 
    raise Conflict, "Databag Item #{params[:id]} already exists" if @data_bag_item
  end
  @data_bag_item.raw_data = raw_data
  @data_bag_item.cdb_save
  display @data_bag_item.raw_data
end

#destroyObject



97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/data_item.rb', line 97

def destroy
  begin
    @data_bag_item = Chef::DataBagItem.cdb_load(params[:data_bag_id], params[:id])
  rescue Chef::Exceptions::CouchDBNotFound => e 
    raise NotFound, "Cannot load data bag #{params[:data_bag_id]} item #{params[:id]}"
  end
  @data_bag_item.cdb_destroy
  @data_bag_item.couchdb_rev = nil
  display @data_bag_item
end

#populate_data_bagObject



32
33
34
35
36
37
38
# File 'app/controllers/data_item.rb', line 32

def populate_data_bag
  begin
    @data_bag = Chef::DataBag.cdb_load(params[:data_bag_id])
  rescue Chef::Exceptions::CouchDBNotFound => e
    raise NotFound, "Cannot load data bag #{params[:data_bag_id]}"
  end
end

#showObject



40
41
42
43
44
45
46
47
# File 'app/controllers/data_item.rb', line 40

def show
  begin
    @data_bag_item = Chef::DataBagItem.cdb_load(params[:data_bag_id], params[:id])
  rescue Chef::Exceptions::CouchDBNotFound => e
    raise NotFound, "Cannot load data bag #{params[:data_bag_id]} item #{params[:id]}"
  end
  display @data_bag_item.raw_data
end

#updateObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/data_item.rb', line 73

def update
  raw_data = nil
  if params.has_key?("inflated_object")
    raw_data = params["inflated_object"].raw_data
  else
    raw_data = params
    raw_data.delete(:action)
    raw_data.delete(:controller)
    raw_data.delete(:data_bag_id)
  end
      
  begin 
    @data_bag_item = Chef::DataBagItem.cdb_load(@data_bag.name, params[:id])
  rescue Chef::Exceptions::CouchDBNotFound => e
    raise NotFound, "Cannot load Databag Item #{params[:id]}"
  end 
  
  @data_bag_item.raw_data = raw_data
  @data_bag_item.cdb_save
  display @data_bag_item.raw_data

end