Module: Sumodev::Actions

Included in:
Generator, Generators::General::Capistrano
Defined in:
lib/sumodev/actions.rb

Instance Method Summary collapse

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.expand_path(original, self.destination_root)
  to = File.expand_path(destination, self.destination_root)

  say_status :copy, relative_to_original_destination_root(to), true

  unless options[: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, options|
      run "git #{cmd} #{options}"
    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(message, &block)
  block.call if block

  git :add => '.'
  git :commit => "-m \"#{message}\""
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.expand_path(file, self.destination_root)
  say_status :replace, relative_to_original_destination_root(path), true

  unless options[: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