Class: Chef::Sandbox
Constant Summary collapse
- DESIGN_DOCUMENT =
{ "version" => 1, "language" => "javascript", "views" => { "all" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "sandbox") { emit(doc.guid, doc); } } EOJS }, "all_id" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "sandbox") { emit(doc.guid, doc.guid); } } EOJS }, "all_incomplete" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "sandbox" && !doc.is_completed) { emit(doc.guid, doc.guid); } } EOJS }, "all_completed" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "sandbox" && doc.is_completed) { emit(doc.guid, doc.guid); } } EOJS }, } }
Instance Attribute Summary collapse
-
#checksums ⇒ Object
list of checksum ids.
-
#couchdb ⇒ Object
Returns the value of attribute couchdb.
-
#couchdb_id ⇒ Object
Returns the value of attribute couchdb_id.
-
#couchdb_rev ⇒ Object
Returns the value of attribute couchdb_rev.
-
#create_time ⇒ Object
Returns the value of attribute create_time.
-
#guid ⇒ Object
(also: #name)
readonly
Returns the value of attribute guid.
-
#is_completed ⇒ Object
(also: #is_completed?)
Returns the value of attribute is_completed.
Class Method Summary collapse
- .cdb_list(inflate = false, couchdb = nil) ⇒ Object
- .cdb_load(guid, couchdb = nil) ⇒ Object
-
.create_design_document(couchdb = nil) ⇒ Object
Couchdb.
- .json_create(o) ⇒ Object
Instance Method Summary collapse
- #cdb_destroy ⇒ Object
- #cdb_save(couchdb = nil) ⇒ Object
- #include?(checksum) ⇒ Boolean (also: #member?)
-
#initialize(guid = nil, couchdb = nil) ⇒ Sandbox
constructor
Creates a new Chef::Sandbox object.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(guid = nil, couchdb = nil) ⇒ Sandbox
Creates a new Chef::Sandbox object.
Returns
- object<Chef::Sandbox>
-
Duh. :)
81 82 83 84 85 86 |
# File 'lib/chef/sandbox.rb', line 81 def initialize(guid=nil, couchdb=nil) @guid = guid || UUIDTools::UUID.random_create.to_s.gsub(/\-/,'').downcase @is_completed = false @create_time = Time.now.iso8601 @checksums = Array.new end |
Instance Attribute Details
#checksums ⇒ Object
list of checksum ids
32 33 34 |
# File 'lib/chef/sandbox.rb', line 32 def checksums @checksums end |
#couchdb ⇒ Object
Returns the value of attribute couchdb.
29 30 31 |
# File 'lib/chef/sandbox.rb', line 29 def couchdb @couchdb end |
#couchdb_id ⇒ Object
Returns the value of attribute couchdb_id.
29 30 31 |
# File 'lib/chef/sandbox.rb', line 29 def couchdb_id @couchdb_id end |
#couchdb_rev ⇒ Object
Returns the value of attribute couchdb_rev.
29 30 31 |
# File 'lib/chef/sandbox.rb', line 29 def couchdb_rev @couchdb_rev end |
#create_time ⇒ Object
Returns the value of attribute create_time.
23 24 25 |
# File 'lib/chef/sandbox.rb', line 23 def create_time @create_time end |
#guid ⇒ Object (readonly) Also known as: name
Returns the value of attribute guid.
25 26 27 |
# File 'lib/chef/sandbox.rb', line 25 def guid @guid end |
#is_completed ⇒ Object Also known as: is_completed?
Returns the value of attribute is_completed.
23 24 25 |
# File 'lib/chef/sandbox.rb', line 23 def is_completed @is_completed end |
Class Method Details
.cdb_list(inflate = false, couchdb = nil) ⇒ Object
133 134 135 136 137 |
# File 'lib/chef/sandbox.rb', line 133 def self.cdb_list(inflate=false, couchdb=nil) rs = (couchdb || Chef::CouchDB.new).list("sandboxes", inflate) lookup = (inflate ? "value" : "key") rs["rows"].collect { |r| r[lookup] } end |
.cdb_load(guid, couchdb = nil) ⇒ Object
139 140 141 142 |
# File 'lib/chef/sandbox.rb', line 139 def self.cdb_load(guid, couchdb=nil) # Probably want to look for a view here at some point (couchdb || Chef::CouchDB.new).load("sandbox", guid) end |
.create_design_document(couchdb = nil) ⇒ Object
Couchdb
129 130 131 |
# File 'lib/chef/sandbox.rb', line 129 def self.create_design_document(couchdb=nil) (couchdb || Chef::CouchDB.new).create_design_document("sandboxes", DESIGN_DOCUMENT) end |
.json_create(o) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/chef/sandbox.rb', line 108 def self.json_create(o) sandbox = new(o['guid']) sandbox.checksums = o['checksums'] sandbox.create_time = o['create_time'] sandbox.is_completed = o['is_completed'] if o.has_key?('_rev') sandbox.couchdb_rev = o["_rev"] o.delete("_rev") end if o.has_key?("_id") sandbox.couchdb_id = o["_id"] #sandbox.index_id = sandbox.couchdb_id o.delete("_id") end sandbox end |
Instance Method Details
#cdb_destroy ⇒ Object
144 145 146 |
# File 'lib/chef/sandbox.rb', line 144 def cdb_destroy (couchdb || Chef::CouchDB.new).delete("sandbox", guid, @couchdb_rev) end |
#cdb_save(couchdb = nil) ⇒ Object
148 149 150 |
# File 'lib/chef/sandbox.rb', line 148 def cdb_save(couchdb=nil) @couchdb_rev = (couchdb || Chef::CouchDB.new).store("sandbox", guid, self)["rev"] end |
#include?(checksum) ⇒ Boolean Also known as: member?
88 89 90 |
# File 'lib/chef/sandbox.rb', line 88 def include?(checksum) @checksums.include?(checksum) end |
#to_json(*a) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef/sandbox.rb', line 94 def to_json(*a) result = { :guid => guid, :name => name, # same as guid, used for id_map :checksums => checksums, :create_time => create_time, :is_completed => is_completed, :json_class => self.class.name, :chef_type => 'sandbox' } result["_rev"] = @couchdb_rev if @couchdb_rev result.to_json(*a) end |