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
14
# File 'lib/formwandler/field_definition.rb', line 10

def initialize(name)
  @name = name
  @transform_blank = false
  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

#transform_blankObject (readonly)

Returns the value of attribute transform_blank.



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

def transform_blank
  @transform_blank
end

Instance Method Details

#configure(opts) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/formwandler/field_definition.rb', line 33

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



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

def hidden_options
  @hidden_options ||= {}
end

#hide_option(name, value = true) ⇒ Object



44
45
46
# File 'lib/formwandler/field_definition.rb', line 44

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

#in_transformationObject



57
58
59
# File 'lib/formwandler/field_definition.rb', line 57

def in_transformation
  value_transformer&.in_transformation
end

#out_transformationObject



61
62
63
# File 'lib/formwandler/field_definition.rb', line 61

def out_transformation
  value_transformer&.out_transformation
end

#transform(allow_blank: false, &block) ⇒ Object



52
53
54
55
# File 'lib/formwandler/field_definition.rb', line 52

def transform(allow_blank: false, &block)
  @transform_blank = allow_blank
  @value_transformer = FieldValueTransformer.new(&block)
end