Class: Presentation::Form::Field

Inherits:
Object
  • Object
show all
Includes:
Presenting::Configurable
Defined in:
lib/presentation/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Presenting::Configurable

#initialize

Instance Attribute Details

#labelObject

the display label of the field



107
108
109
# File 'lib/presentation/form.rb', line 107

def label
  @label ||= name.to_s.titleize
end

#nameObject

the parameter name of the field



113
114
115
# File 'lib/presentation/form.rb', line 113

def name
  @name
end

#typeObject

the widget type for the field. use type_options to pass arguments to the widget.



136
137
138
# File 'lib/presentation/form.rb', line 136

def type
  @type ||= :string
end

#type_optionsObject

unrestricted options storage for the widget type. this could be a list of options for a select, or extra configuration for a calendar widget.



142
143
144
# File 'lib/presentation/form.rb', line 142

def type_options
  @type_options
end

#valueObject

where the value for this field comes from.

  • String: a fixed value

  • Symbol: a method on the record (no arguments)

  • Proc: a custom block that accepts the record as an argument



119
120
121
# File 'lib/presentation/form.rb', line 119

def value
  @value ||= name.to_sym
end

Instance Method Details

#value_from(obj) ⇒ Object

:nodoc:



124
125
126
127
128
129
130
131
132
133
# File 'lib/presentation/form.rb', line 124

def value_from(obj) #:nodoc:
  case value
  when Symbol
    obj.send(value)
  when String
    value
  when Proc
    value.call(obj)
  end
end