Class: Formation::Field
Instance Attribute Summary collapse
-
#fieldset ⇒ Object
readonly
Returns the value of attribute fieldset.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Element
Instance Method Summary collapse
- #field? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Field
constructor
A new instance of Field.
- #required? ⇒ Boolean
Constructor Details
#initialize(name, options = {}) ⇒ Field
Returns a new instance of Field.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/formation/field.rb', line 6 def initialize(name, = {}) @name = name if @fieldset = .delete(:fieldset) @fieldset.fields << self end @type = .delete(:type) || :text @type = Formation::Type.create(self, @type) @label = .delete(:label) || Formation::Util.titleize(@name) @required = .delete(:required) || false # Attach any left-over entries as accessors .each do |key, value| = class << self; self; end .send :attr_accessor, key.to_sym send "#{key}=", value end end |
Instance Attribute Details
#fieldset ⇒ Object (readonly)
Returns the value of attribute fieldset.
3 4 5 |
# File 'lib/formation/field.rb', line 3 def fieldset @fieldset end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/formation/field.rb', line 3 def label @label end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/formation/field.rb', line 3 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/formation/field.rb', line 4 def value @value end |
Instance Method Details
#field? ⇒ Boolean
24 25 26 |
# File 'lib/formation/field.rb', line 24 def field? true end |
#required? ⇒ Boolean
28 29 30 |
# File 'lib/formation/field.rb', line 28 def required? @required end |