Module: Pione::Command::OptionInterface
- Included in:
- CommonOption
- Defined in:
- lib/pione/command/option.rb
Overview
OptionInterface provides basic methods for option modules. All option modules should be extended by this.
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#define(name, &b) ⇒ Object
Define a new option for the command.
-
#use(item_name, option = {}) ⇒ Object
Install the option module with configuration
option.
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
20 21 22 |
# File 'lib/pione/command/option.rb', line 20 def items @items end |
Instance Method Details
#define(name, &b) ⇒ Object
Define a new option for the command.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pione/command/option.rb', line 23 def define(name, &b) item = OptionItem.new.tap do |item| item.name = name b.call(item) end if self.kind_of?(Module) singleton_class.send(:define_method, name) {item} else @items << item end end |
#use(item_name, option = {}) ⇒ Object
Install the option module with configuration option.
37 38 39 |
# File 'lib/pione/command/option.rb', line 37 def use(item_name, option={}) @items << CommonOption.send(item_name).set(option) end |