Class: Gritano::CLI::Thor

Inherits:
Thor
  • Object
show all
Defined in:
lib/gritano/thor.rb

Direct Known Subclasses

Console::Base

Class Method Summary collapse

Class Method Details

.before(methods, &block) ⇒ Object



16
17
18
19
20
# File 'lib/gritano/thor.rb', line 16

def self.before(methods, &block)
  methods.each do |method|
    before_filters[method] = block
  end
end

.before_filtersObject



22
23
24
# File 'lib/gritano/thor.rb', line 22

def self.before_filters
  @before_filters ||= {}
end

.define_task(name, description = "", &block) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/gritano/thor.rb', line 6

def self.define_task(name, description="", &block)
  params = block.parameters.map { |type, name| name.upcase }.join(' ')
  desc("#{name} #{params}".rstrip, description)
  bf = before_filters
  define_method(name.to_sym) do |*params|
    instance_eval(&bf[name]) if bf[name]
    instance_exec(*params, &block)
  end
end