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



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

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



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

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



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

def stop_here!
  @@stop_here = true
end

.stopped_here?Boolean

Returns:

  • (Boolean)


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

def stopped_here?
  @@stop_here
end

.task(name, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# 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|
      Dir.chdir(use_cwd ? Dir.pwd : file_pwd) do
        instance_exec *args, &block
      end
    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