Class: Field::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/field/base.rb

Direct Known Subclasses

Bare, CNPJ, CPF, Email, Float, Form, FormArray, Password, PersonType, Telephone, Text

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/field/base.rb', line 11

def initialize(name, options = {})
  @name    = name
  @options = options
end

Instance Attribute Details

#formObject

Returns the value of attribute form.



5
6
7
# File 'lib/field/base.rb', line 5

def form
  @form
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/field/base.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/field/base.rb', line 4

def options
  @options
end

Class Method Details

.factory(*args) ⇒ Object



7
8
9
# File 'lib/field/base.rb', line 7

def self.factory(*args)
  new(*args)
end

Instance Method Details

#attributeObject



26
27
28
# File 'lib/field/base.rb', line 26

def attribute
  String
end

#inject_attributesObject



30
31
32
# File 'lib/field/base.rb', line 30

def inject_attributes
  @container.attribute @name, attribute
end

#inject_validationsObject



34
35
36
37
38
# File 'lib/field/base.rb', line 34

def inject_validations
  if @options.any?
    @container.send(:validates, @name, @options)
  end
end

#presenter_classObject



44
45
46
# File 'lib/field/base.rb', line 44

def presenter_class
  nil
end

#setup_container(container) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/field/base.rb', line 16

def setup_container(container)
  @container = container

  if Helper.container_is_virtus?(container)
    inject_attributes
  end

  inject_validations
end

#valueObject



40
41
42
# File 'lib/field/base.rb', line 40

def value
  @form.send(name) if @form
end