Class: Chap::Hook
Constant Summary
Constants included from SpecialMethods
SpecialMethods::SPECIAL_METHODS
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(path, config) ⇒ Hook
constructor
A new instance of Hook.
- #rm_rvmrc ⇒ Object
- #run(cmd) ⇒ Object
-
#symlink_configs ⇒ Object
hook helper methods.
- #with(prepend) ⇒ Object
Methods included from SpecialMethods
Constructor Details
#initialize(path, config) ⇒ Hook
Returns a new instance of Hook.
6 7 8 9 10 |
# File 'lib/chap/hook.rb', line 6 def initialize(path, config) @path = path @config = config @with = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/chap/hook.rb', line 5 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/chap/hook.rb', line 5 def @options end |
Instance Method Details
#evaluate ⇒ Object
12 13 14 |
# File 'lib/chap/hook.rb', line 12 def evaluate instance_eval(File.read(@path), @path) end |
#rm_rvmrc ⇒ Object
31 32 33 34 35 36 |
# File 'lib/chap/hook.rb', line 31 def rm_rvmrc %w[.rvmrc .ruby-version].each do |file| path = "#{release_path}/#{file}" run "rm -f #{path}" if File.exist?(path) end end |
#run(cmd) ⇒ Object
44 45 46 47 |
# File 'lib/chap/hook.rb', line 44 def run(cmd) cmd = "#{@with} #{cmd}" config.run(cmd) end |
#symlink_configs ⇒ Object
hook helper methods
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chap/hook.rb', line 17 def symlink_configs paths = Dir.glob("#{shared_path}/config/**/*"). select {|p| File.file?(p) } paths.each do |src| relative_path = src.gsub(%r{.*config/},'config/') dest = "#{release_path}/#{relative_path}" # make sure the directory exist for symlink creation dirname = File.dirname(dest) FileUtils.mkdir_p(dirname) unless File.exist?(dirname) FileUtils.rm_rf(dest) if File.exist?(dest) FileUtils.ln_s(src,dest) end end |
#with(prepend) ⇒ Object
38 39 40 41 42 |
# File 'lib/chap/hook.rb', line 38 def with(prepend) prev, @with = @with, prepend yield @with = prev end |