Module: Sumodev::Actions
- Included in:
- Generator, Generators::General::Capistrano
- Defined in:
- lib/sumodev/actions.rb
Instance Method Summary collapse
- #copy_dest_file(original, destination) ⇒ Object
- #git(commands = {}) ⇒ Object
- #git_track(message, &block) ⇒ Object
- #replace_in_file(file, replacements) ⇒ Object
Instance Method Details
#copy_dest_file(original, destination) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/sumodev/actions.rb', line 2 def copy_dest_file original, destination from = File.(original, self.destination_root) to = File.(destination, self.destination_root) say_status :copy, relative_to_original_destination_root(to), true unless [:pretend] FileUtils.cp from, to end end |
#git(commands = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/sumodev/actions.rb', line 28 def git(commands = {}) if commands.respond_to?(:each) commands.each do |cmd, | run "git #{cmd} #{}" end else run "git #{commands}" end end |
#git_track(message, &block) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/sumodev/actions.rb', line 38 def git_track(, &block) block.call if block git :add => '.' git :commit => "-m \"#{}\"" end |
#replace_in_file(file, replacements) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sumodev/actions.rb', line 13 def replace_in_file file, replacements return unless behavior == :invoke path = File.(file, self.destination_root) say_status :replace, relative_to_original_destination_root(path), true unless [:pretend] content = File.binread(path) replacements.each do |match, replace| content.gsub!(match, replace.to_s) File.open(path, 'wb') {|f| f.write(content)} end end end |