Class: VirtualMaster::Callbacks::Callback
- Inherits:
-
Object
- Object
- VirtualMaster::Callbacks::Callback
- Defined in:
- lib/vmaster/callbacks.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #after(event, &block) ⇒ Object
- #before(event, &block) ⇒ Object
- #fire(event, phase, options, server) ⇒ Object
- #has_option? ⇒ Boolean
-
#initialize(name, &block) ⇒ Callback
constructor
A new instance of Callback.
-
#option(name, type, description) ⇒ Object
command line options provide configuration.
- #to_option ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Callback
Returns a new instance of Callback.
15 16 17 18 19 20 21 |
# File 'lib/vmaster/callbacks.rb', line 15 def initialize(name, &block) @name = name @blocks = {} @option = nil instance_eval &block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/vmaster/callbacks.rb', line 13 def name @name end |
Instance Method Details
#after(event, &block) ⇒ Object
27 28 29 |
# File 'lib/vmaster/callbacks.rb', line 27 def after(event, &block) store_callback(event, :after, &block) end |
#before(event, &block) ⇒ Object
23 24 25 |
# File 'lib/vmaster/callbacks.rb', line 23 def before(event, &block) store_callback(event, :before, &block) end |
#fire(event, phase, options, server) ⇒ Object
44 45 46 |
# File 'lib/vmaster/callbacks.rb', line 44 def fire(event, phase, , server) @blocks[event][phase].call(, server) if includes?(event, phase) && [@option[:name]] end |
#has_option? ⇒ Boolean
52 53 54 |
# File 'lib/vmaster/callbacks.rb', line 52 def has_option? not @option.nil? end |
#option(name, type, description) ⇒ Object
command line options provide configuration
TODO support for multiple options
36 37 38 39 40 41 42 |
# File 'lib/vmaster/callbacks.rb', line 36 def option(name, type, description) @option = { :name => name, :type => type, :description => description } end |
#to_option ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vmaster/callbacks.rb', line 56 def to_option arguments = [] option_name = "--#{@option[:name]}" option_name << " VALUE" if @option[:type] arguments << option_name arguments << @option[:type] if @option[:type] arguments << @option[:description] end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/vmaster/callbacks.rb', line 48 def to_s @blocks.inspect end |