Module: VPS
- Extended by:
- VPS
- Included in:
- VPS
- Defined in:
- lib/vps.rb,
lib/vps/cli.rb,
lib/vps/version.rb,
lib/vps/cli/domain.rb,
lib/vps/cli/service.rb,
lib/vps/cli/playbook.rb,
lib/vps/cli/upstream.rb,
lib/vps/cli/playbook/state.rb,
lib/vps/cli/playbook/tasks.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- ROOT =
File.("#{__FILE__}/../..")
- PLAYBOOKS =
"#{ROOT}/playbooks"- TEMPLATES =
"#{ROOT}/templates"- MAJOR =
0- MINOR =
3- TINY =
1- VERSION =
[MAJOR, MINOR, TINY].join(".")
Instance Method Summary collapse
- #config_path(host, path = "config.yml") ⇒ Object
- #read_config(host, key = nil) ⇒ Object
- #read_template(path) ⇒ Object
- #write_config(host, changes) ⇒ Object
Instance Method Details
#config_path(host, path = "config.yml") ⇒ Object
11 12 13 |
# File 'lib/vps.rb', line 11 def config_path(host, path = "config.yml") File.("~/.vps/#{host}/#{path}") end |
#read_config(host, key = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vps.rb', line 19 def read_config(host, key = nil) config = if File.exists?(path = config_path(host)) YAML.load_file(path) elsif key.nil? { :user => nil, :tool => nil, :release_path => nil, :services => nil, :upstreams => nil, :volumes => nil, :preload => nil, :postload => nil } end if config config = with_indifferent_access(config) if key with_indifferent_access(config[key]) else config[:services] ||= {} config[:upstreams] ||= [] config[:volumes] ||= [] config end end end |
#read_template(path) ⇒ Object
15 16 17 |
# File 'lib/vps.rb', line 15 def read_template(path) File.read("#{TEMPLATES}/#{path}") end |
#write_config(host, changes) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vps.rb', line 49 def write_config(host, changes) config = read_config(host) || {} changed = false %w(services upstreams volumes).each do |key| value = changes[key] changes[key] = nil if value && value.empty? end changes.each do |key, value| if !config.include?(key) || (config[key] != value) config[key] = value changed = true end end if changed path = config_path(host) config = JSON.parse(config.to_json) FileUtils.mkdir_p(File.dirname(path)) File.write(path, config.to_yaml) end end |