Module: HasControls

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controlsObject (readonly)

Returns the value of attribute controls.



3
4
5
# File 'lib/interview/has_controls.rb', line 3

def controls
  @controls
end

Class Method Details

.included(mod) ⇒ Object



31
32
33
# File 'lib/interview/has_controls.rb', line 31

def self.included(mod)
  mod.extend ClassMethods
end

Instance Method Details

#add_control(control) {|control| ... } ⇒ Object

Yields:

  • (control)


10
11
12
13
14
# File 'lib/interview/has_controls.rb', line 10

def add_control(control, &block)
  control.parent = self
  yield(control) if block_given?
  @controls << control
end

#add_controls(controls) ⇒ Object



16
17
18
19
# File 'lib/interview/has_controls.rb', line 16

def add_controls(controls)
  controls.each { |control| control.parent = self }
  @controls += controls
end

#initialize(params = {}) ⇒ Object



5
6
7
8
# File 'lib/interview/has_controls.rb', line 5

def initialize(params={})
  super
  @controls = self.class.definition.build_controls_for self
end

#siblingsObject



21
22
23
24
25
26
27
28
29
# File 'lib/interview/has_controls.rb', line 21

def siblings
  return @controls.map do |control|
    if control.respond_to? :siblings
      [control] + control.siblings
    else
      control
    end
  end.flatten
end