Class: GV::Valley::App
- Inherits:
-
Object
- Object
- GV::Valley::App
- Defined in:
- lib/gv/valley/app.rb
Constant Summary collapse
- PORT =
5000
Class Method Summary collapse
- .all ⇒ Object
- .create(name) ⇒ Object
- .default_config(name) ⇒ Object
- .default_domain(name) ⇒ Object
- .delete(name) ⇒ Object
- .domain ⇒ Object
- .ensure_defaults(data) ⇒ Object
- .etcd_clt ⇒ Object
- .find(name) ⇒ Object
- .find!(name) ⇒ Object
- .save(name, data) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete ⇒ Object
-
#initialize(attributes = {}) ⇒ App
constructor
A new instance of App.
- #save ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ App
Returns a new instance of App.
83 84 85 86 87 |
# File 'lib/gv/valley/app.rb', line 83 def initialize attributes = {} @attributes = attributes @name = @attributes['name'] @attributes = attributes end |
Class Method Details
.all ⇒ Object
27 28 29 |
# File 'lib/gv/valley/app.rb', line 27 def all etcd_clt.get("/apps").children.map{ |node| find(File.basename(node.key)) } end |
.create(name) ⇒ Object
44 45 46 47 |
# File 'lib/gv/valley/app.rb', line 44 def create name save name, {"name" => name, "config" => default_config(name), "ps" => {}, "domains" => [default_domain(name)]} find name end |
.default_config(name) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/gv/valley/app.rb', line 61 def default_config name config = { "SLUG_URL" => "#{GV::Valley::FileServer.service.url}/#{name}/slug.tgz", "PORT" => PORT } end |
.default_domain(name) ⇒ Object
68 69 70 |
# File 'lib/gv/valley/app.rb', line 68 def default_domain name "#{name}.#{self.domain}" end |
.delete(name) ⇒ Object
53 54 55 |
# File 'lib/gv/valley/app.rb', line 53 def delete name etcd_clt.delete("/apps/#{name}",{recursive: true}) rescue nil end |
.domain ⇒ Object
57 58 59 |
# File 'lib/gv/valley/app.rb', line 57 def domain GV::Bedrock::Config.service.get("domain") end |
.ensure_defaults(data) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/gv/valley/app.rb', line 72 def ensure_defaults data data["config"] ||= {} data["config"].update(default_config(data["name"])) data["domains"] ||= [] data["domains"] << default_domain(data["name"]) unless data["domains"].include? default_domain(data["name"]) data end |
.etcd_clt ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/gv/valley/app.rb', line 17 def etcd_clt @@etcd_clt ||= begin server = GV::Valley::Etcd.service ::Etcd.client(config = { host: server.external_ip, port: server.port }) end end |
.find(name) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/gv/valley/app.rb', line 31 def find name begin find! name rescue ::Etcd::KeyNotFound nil end end |
.find!(name) ⇒ Object
39 40 41 42 |
# File 'lib/gv/valley/app.rb', line 39 def find! name value = etcd_clt.get("/apps/#{name}").value new(ensure_defaults(JSON.load(value))) end |
.save(name, data) ⇒ Object
49 50 51 |
# File 'lib/gv/valley/app.rb', line 49 def save name, data etcd_clt.set("/apps/#{name}", { value: JSON.dump(ensure_defaults(data)) }) end |
Instance Method Details
#[](key) ⇒ Object
97 98 99 |
# File 'lib/gv/valley/app.rb', line 97 def [](key) @attributes[key] end |
#[]=(key, value) ⇒ Object
101 102 103 |
# File 'lib/gv/valley/app.rb', line 101 def []=(key,value) @attributes[key]=value end |
#delete ⇒ Object
93 94 95 |
# File 'lib/gv/valley/app.rb', line 93 def delete self.class.delete @name end |
#save ⇒ Object
89 90 91 |
# File 'lib/gv/valley/app.rb', line 89 def save self.class.save(@name,@attributes) end |