Class: Chap::Hook
- Inherits:
-
Object
- Object
- Chap::Hook
- Includes:
- Benchmarking, SpecialMethods
- Defined in:
- lib/chap/hook.rb
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 Benchmarking
#benchmarks, included, #report_benchmarks, #shorten_name
Methods included from SpecialMethods
Constructor Details
#initialize(path, config) ⇒ Hook
Returns a new instance of Hook.
7 8 9 10 11 |
# File 'lib/chap/hook.rb', line 7 def initialize(path, config) @path = path @config = config @with = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/chap/hook.rb', line 6 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/chap/hook.rb', line 6 def @options end |
Instance Method Details
#evaluate ⇒ Object
13 14 15 |
# File 'lib/chap/hook.rb', line 13 def evaluate instance_eval(File.read(@path), @path) end |
#rm_rvmrc ⇒ Object
32 33 34 35 36 37 |
# File 'lib/chap/hook.rb', line 32 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
45 46 47 48 |
# File 'lib/chap/hook.rb', line 45 def run(cmd) cmd = "#{@with} #{cmd}" config.run(cmd) end |
#symlink_configs ⇒ Object
hook helper methods
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/chap/hook.rb', line 18 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
39 40 41 42 43 |
# File 'lib/chap/hook.rb', line 39 def with(prepend) prev, @with = @with, prepend yield @with = prev end |