Class: Formwandler::FieldDefinition
- Inherits:
-
Object
- Object
- Formwandler::FieldDefinition
- Defined in:
- lib/formwandler/field_definition.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#default ⇒ Object
Returns the value of attribute default.
-
#delocalize ⇒ Object
Returns the value of attribute delocalize.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#model ⇒ Object
Returns the value of attribute model.
-
#model_class ⇒ Object
Returns the value of attribute model_class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#readonly ⇒ Object
Returns the value of attribute readonly.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #configure(opts) ⇒ Object
- #hidden_options ⇒ Object
- #hide_option(name, value = true) ⇒ Object
- #in_transformation ⇒ Object
-
#initialize(name) ⇒ FieldDefinition
constructor
A new instance of FieldDefinition.
- #out_transformation ⇒ Object
- #transform(&block) ⇒ Object
Constructor Details
#initialize(name) ⇒ FieldDefinition
Returns a new instance of FieldDefinition.
10 11 12 13 |
# File 'lib/formwandler/field_definition.rb', line 10 def initialize(name) @name = name set_defaults end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def array @array end |
#default ⇒ Object
Returns the value of attribute default.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def default @default end |
#delocalize ⇒ Object
Returns the value of attribute delocalize.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def delocalize @delocalize end |
#disabled ⇒ Object
Returns the value of attribute disabled.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def disabled @disabled end |
#hidden ⇒ Object
Returns the value of attribute hidden.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def hidden @hidden end |
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def model @model end |
#model_class ⇒ Object
Returns the value of attribute model_class.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def model_class @model_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/formwandler/field_definition.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def @options end |
#readonly ⇒ Object
Returns the value of attribute readonly.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def readonly @readonly end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/formwandler/field_definition.rb', line 8 def source @source end |
Instance Method Details
#configure(opts) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/formwandler/field_definition.rb', line 32 def configure(opts) model = opts[:model] model_class = opts[:model_class] || model set_model model, model_class opts.except(:model, :model_class).each do |key, value| send("#{key}=", value) rescue NoMethodError raise ArgumentError, "Invalid option #{key}" end end |
#hidden_options ⇒ Object
47 48 49 |
# File 'lib/formwandler/field_definition.rb', line 47 def @hidden_options ||= {} end |
#hide_option(name, value = true) ⇒ Object
43 44 45 |
# File 'lib/formwandler/field_definition.rb', line 43 def hide_option(name, value = true) [name.to_s] = value end |
#in_transformation ⇒ Object
55 56 57 |
# File 'lib/formwandler/field_definition.rb', line 55 def in_transformation value_transformer&.in_transformation end |
#out_transformation ⇒ Object
59 60 61 |
# File 'lib/formwandler/field_definition.rb', line 59 def out_transformation value_transformer&.out_transformation end |
#transform(&block) ⇒ Object
51 52 53 |
# File 'lib/formwandler/field_definition.rb', line 51 def transform(&block) @value_transformer = FieldValueTransformer.new(&block) end |