Class: Babushka::Cmdline::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/babushka/cmdline/handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, opt_definer) ⇒ Handler

Returns a new instance of Handler.



36
37
38
# File 'lib/babushka/cmdline/handler.rb', line 36

def initialize name, description, opt_definer
  @name, @description, @opt_definer = name, description, (opt_definer || L{})
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



34
35
36
# File 'lib/babushka/cmdline/handler.rb', line 34

def description
  @description
end

#handlerObject (readonly)

Returns the value of attribute handler.



34
35
36
# File 'lib/babushka/cmdline/handler.rb', line 34

def handler
  @handler
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/babushka/cmdline/handler.rb', line 34

def name
  @name
end

#opt_definerObject (readonly)

Returns the value of attribute opt_definer.



34
35
36
# File 'lib/babushka/cmdline/handler.rb', line 34

def opt_definer
  @opt_definer
end

Class Method Details

.abbrevObject



26
27
28
# File 'lib/babushka/cmdline/handler.rb', line 26

def self.abbrev
  all.map(&:name).abbrev
end

.add(name, description, opt_definer) ⇒ Object



16
17
18
19
20
# File 'lib/babushka/cmdline/handler.rb', line 16

def self.add name, description, opt_definer
  Handler.new(name, description, opt_definer).tap {|handler|
    (@handlers ||= []).push handler
  }
end

.allObject



22
23
24
# File 'lib/babushka/cmdline/handler.rb', line 22

def self.all
  @handlers.reject {|h| h.name == 'global' }
end

.for(name) ⇒ Object



30
31
32
# File 'lib/babushka/cmdline/handler.rb', line 30

def self.for name
  @handlers.detect {|h| h.name == name }
end

Instance Method Details

#run(&handler) ⇒ Object



40
41
42
# File 'lib/babushka/cmdline/handler.rb', line 40

def run &handler
  @handler = handler
end