Class: ControlDef
- Inherits:
-
Object
- Object
- ControlDef
- Defined in:
- lib/interview/control_def.rb
Instance Attribute Summary collapse
-
#controls ⇒ Object
readonly
Returns the value of attribute controls.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #build(params = {}) ⇒ Object
- #build_controls_for(parent_control) ⇒ Object
- #control(klass, params = {}) {|control| ... } ⇒ Object
- #deep_dup ⇒ Object
-
#initialize(klass, params = {}) ⇒ ControlDef
constructor
A new instance of ControlDef.
Constructor Details
#initialize(klass, params = {}) ⇒ ControlDef
Returns a new instance of ControlDef.
6 7 8 9 10 |
# File 'lib/interview/control_def.rb', line 6 def initialize(klass, params={}) @klass = klass.to_sym @params = params @controls = [] end |
Instance Attribute Details
#controls ⇒ Object (readonly)
Returns the value of attribute controls.
4 5 6 |
# File 'lib/interview/control_def.rb', line 4 def controls @controls end |
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/interview/control_def.rb', line 3 def klass @klass end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/interview/control_def.rb', line 4 def params @params end |
Instance Method Details
#build(params = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/interview/control_def.rb', line 18 def build(params={}) control = Object::const_get("#{@klass.to_s.camelcase}").new(@params.merge(params)) if control.respond_to? :add_controls control.add_controls build_controls_for(control) end return control end |
#build_controls_for(parent_control) ⇒ Object
26 27 28 |
# File 'lib/interview/control_def.rb', line 26 def build_controls_for(parent_control) return @controls.map { |c| c.build(parent: parent_control) } end |
#control(klass, params = {}) {|control| ... } ⇒ Object
12 13 14 15 16 |
# File 'lib/interview/control_def.rb', line 12 def control(klass, params={}, &block) control = ControlDef.new(klass, params) @controls << control yield(control) if block_given? end |
#deep_dup ⇒ Object
30 31 32 33 34 |
# File 'lib/interview/control_def.rb', line 30 def deep_dup new_definition = self.class.new(@klass, @params.deep_dup) new_definition.instance_variable_set :@controls, @controls.deep_dup return new_definition end |