Module: GuardHelpers::InitdHelper

Includes:
BaseHelper, RoHelpers::SetEnvsHelper
Defined in:
lib/guard_helpers/initd_helper.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from BaseHelper

#handle_all_paths, #handle_each_path, included, #paths

Instance Method Details

#run_on_modifications(paths) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/guard_helpers/initd_helper.rb', line 21

def run_on_modifications(paths)
  super if defined? super

  paths.flatten.each do |p|
    if p.match(%r{(.+)\.erb})
      file = File.basename(p).gsub(%r{\.erb}) do |m|
        ""
      end
      initd file
    end
  end
end

#startObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/guard_helpers/initd_helper.rb', line 34

def start
  super if defined? super
  cmds = ::Pry::CommandSet.new do

    pry_cmd "modified", "" do |*args|
      Find.find("etc/init.d").sort_by do |f|
        test(?M, f)
      end.map do |f|
        Out.out "#{f}: #{test(?M, f)}"
      end
    end
  end

  ::Pry::Commands.import cmds


  cmds = Pry::CommandSet.new do
    pry_cmd "template_ctn" do |file|
      ctn = File.read(File.join("templates", "#{file}.erb"))
      result = ERB.new(ctn).result(binding())
      puts result
    end

    pry_cmd "initd" do
      Out.out "Building ro_server.erb file:#{::File.basename __FILE__} line:#{__LINE__}", "green"
      ctn = File.read("ro_server.erb")
      result = ERB.new(ctn).result(binding)
      to = "ro_server"
      File.write(to, result)
      remote = File.join('/etc/init.d', "ro_server")
      upload to, remote
      remote_bash "chmod 755 #{remote}"
    end
  end

  Pry::Commands.import cmds
end