Class: C42::C42file

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/c42/c42file.rb

Constant Summary collapse

@@pkg_name =
nil
@@use_cwd =
nil
@@file_pwd =
%x{pwd}
@@stop_here =
false

Class Method Summary collapse

Class Method Details

.__original_descObject



41
# File 'lib/c42/c42file.rb', line 41

alias_method :__original_desc, :desc

.desc(name, *args) ⇒ Object



42
43
44
# File 'lib/c42/c42file.rb', line 42

def desc(name, *args)
  self.send(:__original_desc, *(["#{@@pkg_name}#{name}"] | (args || [])))
end

.package(pkg_name, &block) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/c42/c42file.rb', line 79

def package(pkg_name, &block)
  self.instance_eval do
    @@pkg_name = "#{pkg_name}:"
    yield  
    @@pkg_name = nil
  end
end

.shell_task(name, command, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/c42/c42file.rb', line 66

def shell_task(name, command, options = {})
  options = {message: :system, recipient: Kernel, use_cwd: false}.merge(options || {})
  task :"#{name}" do |*args|
    cmd = ([command] | (args || [])).flatten
    (options[:recipient]).send(
      options[:message], 
      *(
        command.is_a?(String) ? [cmd.join(" ")] : cmd
      )
    )
  end
end

.stop_here!Object



87
88
89
# File 'lib/c42/c42file.rb', line 87

def stop_here!
  @@stop_here = true
end

.stopped_here?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/c42/c42file.rb', line 91

def stopped_here?
  @@stop_here
end

.task(name, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/c42/c42file.rb', line 53

def task(name, &block)
  use_cwd = @@use_cwd
  file_pwd = @@file_pwd
  self.instance_eval do
    define_method :"#{@@pkg_name}#{name}" do |*args|
      old_cwd = Dir.pwd
      Dir.chdir(file_pwd) unless use_cwd
      instance_exec *args, &block
      Dir.chdir(old_cwd) unless use_cwd
    end
  end
end

.use_cwd(&block) ⇒ Object



46
47
48
49
50
# File 'lib/c42/c42file.rb', line 46

def use_cwd(&block)
  @@use_cwd = true
  yield
  @@use_cwd = nil
end