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.


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

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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description


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

def description
  @description
end

#handlerObject (readonly)

Returns the value of attribute handler


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

def handler
  @handler
end

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

#opt_definerObject (readonly)

Returns the value of attribute opt_definer


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

def opt_definer
  @opt_definer
end

Class Method Details

.abbrevObject


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

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

.add(name, description, opt_definer) ⇒ Object


11
12
13
14
15
# File 'lib/babushka/cmdline/handler.rb', line 11

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

.allObject


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

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

.for(name) ⇒ Object


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

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

Instance Method Details

#run(&handler) ⇒ Object


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

def run &handler
  @handler = handler
end