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) ⇒ 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

#arrayObject

Returns the value of attribute array.



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

def array
  @array
end

#defaultObject

Returns the value of attribute default.



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

def default
  @default
end

#delocalizeObject

Returns the value of attribute delocalize.



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

def delocalize
  @delocalize
end

#disabledObject

Returns the value of attribute disabled.



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

def disabled
  @disabled
end

#hiddenObject

Returns the value of attribute hidden.



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

def hidden
  @hidden
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#model_classObject

Returns the value of attribute model_class.



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

def model_class
  @model_class
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

Returns the value of attribute options.



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

def options
  @options
end

#readonlyObject

Returns the value of attribute readonly.



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

def readonly
  @readonly
end

#sourceObject

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_optionsObject



47
48
49
# File 'lib/formwandler/field_definition.rb', line 47

def hidden_options
  @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)
  hidden_options[name.to_s] = value
end

#in_transformationObject



55
56
57
# File 'lib/formwandler/field_definition.rb', line 55

def in_transformation
  value_transformer&.in_transformation
end

#out_transformationObject



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