Class: Formation::Field

Inherits:
Element show all
Defined in:
lib/formation/field.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#name

Instance Method Summary collapse

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, options = {})
  @name = name
  if @fieldset = options.delete(:fieldset)
    @fieldset.fields << self
  end
  @type = options.delete(:type) || :text
  @type = Formation::Type.create(self, @type)
  @label = options.delete(:label) || Formation::Util.titleize(@name)
  @required = options.delete(:required) || false
  
  # Attach any left-over entries as accessors
  options.each do |key, value|
    metaclass = class << self; self; end
    metaclass.send :attr_accessor, key.to_sym
    send "#{key}=", value
  end
end

Instance Attribute Details

#fieldsetObject (readonly)

Returns the value of attribute fieldset.



3
4
5
# File 'lib/formation/field.rb', line 3

def fieldset
  @fieldset
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/formation/field.rb', line 3

def label
  @label
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/formation/field.rb', line 3

def type
  @type
end

#valueObject

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/formation/field.rb', line 24

def field?
  true
end

#required?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/formation/field.rb', line 28

def required?
  @required
end