Class: Formwandler::FieldDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/formwandler/field_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hidden: false, disabled: false, default: nil, delocalize: nil, model: nil, source: nil, options: nil, array: false) ⇒ FieldDefinition

Returns a new instance of FieldDefinition.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/formwandler/field_definition.rb', line 9

def initialize(name, hidden: false, disabled: false, default: nil, delocalize: nil, model: nil, source: nil, options: nil, array: false)
  @name = name
  @hidden = hidden
  @disabled = disabled
  @default = default
  @delocalize = delocalize
  @model = model
  @source = source || name
  @options = options
  @array = array
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def array
  @array
end

#defaultObject (readonly)

Returns the value of attribute default.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def default
  @default
end

#delocalizeObject (readonly)

Returns the value of attribute delocalize.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def delocalize
  @delocalize
end

#disabledObject (readonly)

Returns the value of attribute disabled.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def disabled
  @disabled
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def hidden
  @hidden
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def options
  @options
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/formwandler/field_definition.rb', line 7

def source
  @source
end

Instance Method Details

#hidden_optionsObject



25
26
27
# File 'lib/formwandler/field_definition.rb', line 25

def hidden_options
  @hidden_options ||= {}
end

#hide_option(name, value = true) ⇒ Object



21
22
23
# File 'lib/formwandler/field_definition.rb', line 21

def hide_option(name, value = true)
  hidden_options[name.to_s] = value
end

#in_transformationObject



33
34
35
# File 'lib/formwandler/field_definition.rb', line 33

def in_transformation
  value_transformer&.in_transformation
end

#out_transformationObject



37
38
39
# File 'lib/formwandler/field_definition.rb', line 37

def out_transformation
  value_transformer&.out_transformation
end

#transform(&block) ⇒ Object



29
30
31
# File 'lib/formwandler/field_definition.rb', line 29

def transform(&block)
  @value_transformer = FieldValueTransformer.new(&block)
end