Module: Instrument::ControlBuilder
- Defined in:
- lib/instrument/control_builder.rb
Overview
A module which you can mixin to allow for abbreviated control creation.
Example
include Instrument::ControlBuilder
select_control(:name => "base", :selections => [
{:label => "One", :value => "1"},
{:label => "Two", :value => "2"},
{:label => "Three", :value => "3"},
{:label => "Four", :value => "4"}
]).to_xhtml
Instance Method Summary collapse
-
#method_missing(method, *params, &block) ⇒ Object
Initializes Instrument::Control subclasses by name.
-
#respond_to?(method, include_private = false) ⇒ Boolean
Returns true if the control builder responds to the given message.
-
#select(*params, &block) ⇒ Object
Prevents Kernel#select from being accidentally called.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params, &block) ⇒ Object
Initializes Instrument::Control subclasses by name.
@param [Symbol] method the method being called
@param [Array] params the method's parameters
@param [Proc] block the block being passed to the method
@return [Instrument::Control] the control being created
@raise NoMethodError if the method wasn't handled
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/instrument/control_builder.rb', line 70 def method_missing(method, *params, &block) control_class = ::Instrument::Control.lookup(method.to_s) if control_class != nil return control_class.new(*params, &block) else raise NoMethodError, "undefined method `#{method}' for " + "#{self.inspect}:#{self.class.name}" end end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
Returns true if the control builder responds to the given message.
@return [Boolean] if the control builder responds
56 57 58 59 60 |
# File 'lib/instrument/control_builder.rb', line 56 def respond_to?(method, include_private=false) control_class = ::Instrument::Control.lookup(method.to_s) return true if control_class != nil super end |
#select(*params, &block) ⇒ Object
Prevents Kernel#select from being accidentally called.
@param [Array] params the method's parameters
@param [Proc] block the block being passed to the method
@return [Instrument::Control] the control being created
48 49 50 |
# File 'lib/instrument/control_builder.rb', line 48 def select(*params, &block) # :nodoc: return self.method_missing(:select, *params, &block) end |