Class: Chap::Config
- Inherits:
-
Object
- Object
- Chap::Config
- Defined in:
- lib/chap/config.rb
Instance Attribute Summary collapse
-
#chap ⇒ Object
readonly
Returns the value of attribute chap.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #cached_path ⇒ Object
- #chap_log_path ⇒ Object
- #current_path ⇒ Object
- #deploy_to ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #latest_release ⇒ Object
-
#load_json(key) ⇒ Object
the chap.json and node.json is assumed to be in th same folder as chap.yml if a relative path is given.
- #log(msg) ⇒ Object
- #logger ⇒ Object
-
#override_timestamp(timestamp) ⇒ Object
useful so we can test hooks.
-
#release_path ⇒ Object
special attributes added to chap.
- #run(cmd) ⇒ Object
- #shared_path ⇒ Object
- #strategy ⇒ Object
- #timestamp ⇒ Object
- #yaml ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
4 5 6 7 8 |
# File 'lib/chap/config.rb', line 4 def initialize(={}) = # preload all config files so validatation happens before deploys _ = yaml, chap, node end |
Instance Attribute Details
#chap ⇒ Object (readonly)
Returns the value of attribute chap.
3 4 5 |
# File 'lib/chap/config.rb', line 3 def chap @chap end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
3 4 5 |
# File 'lib/chap/config.rb', line 3 def node @node end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/chap/config.rb', line 3 def end |
Instance Method Details
#cached_path ⇒ Object
76 77 78 79 80 |
# File 'lib/chap/config.rb', line 76 def cached_path return @cached_path if @cached_path path = chap[:repo].split(':').last.sub('.git','') @cached_path = "#{shared_path}/cache/#{strategy}/#{path}" end |
#chap_log_path ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/chap/config.rb', line 99 def chap_log_path return @chap_log_path if @chap_log_path dir = "#{shared_path}/chap" FileUtils.mkdir_p(dir) unless File.exist?(dir) @chap_log_path = "#{dir}/chap.log" system("cat /dev/null > #{@chap_log_path}") @chap_log_path end |
#current_path ⇒ Object
68 69 70 |
# File 'lib/chap/config.rb', line 68 def current_path "#{deploy_to}/current" end |
#deploy_to ⇒ Object
59 60 61 |
# File 'lib/chap/config.rb', line 59 def deploy_to chap[:deploy_to] end |
#latest_release ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/chap/config.rb', line 82 def latest_release return @latest_release if @latest_release @latest_release = Dir.glob("#{deploy_to}/releases/*"). select {|p| File.directory?(p) }. sort. last end |
#load_json(key) ⇒ Object
the chap.json and node.json is assumed to be in th same folder as chap.yml if a relative path is given
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chap/config.rb', line 35 def load_json(key) path = if yaml[key] =~ %r{^/} # root path given yaml[key] else # relative path dirname = File.dirname([:config]) "#{dirname}/#{yaml[key]}" end if File.exist?(path) Mash.from_hash(JSON.parse(IO.read(path))) else puts "ERROR: #{key}.json config does not exist at: #{path}" exit 1 end end |
#log(msg) ⇒ Object
94 95 96 97 |
# File 'lib/chap/config.rb', line 94 def log(msg) puts msg unless [:quiet] logger.info(msg) end |
#logger ⇒ Object
108 109 110 111 112 113 |
# File 'lib/chap/config.rb', line 108 def logger return @logger if @logger @logger = Logger.new(chap_log_path) # @logger.level = Logger::WARN @logger end |
#override_timestamp(timestamp) ⇒ Object
useful so we can test hooks
55 56 57 |
# File 'lib/chap/config.rb', line 55 def () = end |
#release_path ⇒ Object
special attributes added to chap
64 65 66 |
# File 'lib/chap/config.rb', line 64 def release_path "#{deploy_to}/releases/#{timestamp}" end |
#run(cmd) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/chap/config.rb', line 115 def run(cmd) log "Running: #{cmd}" cmd = "#{cmd} 2>&1" unless cmd.include?(" > ") out = `#{cmd}` log out raise "DeployError" if $?.exitstatus > 0 end |
#shared_path ⇒ Object
72 73 74 |
# File 'lib/chap/config.rb', line 72 def shared_path "#{deploy_to}/shared" end |
#strategy ⇒ Object
90 91 92 |
# File 'lib/chap/config.rb', line 90 def strategy chap[:strategy] || 'checkout' end |
#timestamp ⇒ Object
50 51 52 |
# File 'lib/chap/config.rb', line 50 def ||= Time.now.strftime("%Y%m%d%H%M%S") end |
#yaml ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/chap/config.rb', line 10 def yaml path = [:config] if File.exist?(path) @yaml ||= Mash.from_hash(YAML.load(IO.read(path))) else puts "ERROR: chap.yaml config does not exist at: #{path}" exit 1 end end |