Module: Faire::Attributes
- Defined in:
- lib/faire/attributes.rb
Instance Method Summary collapse
- #date(name, attributes = {}) ⇒ Object
- #defaults ⇒ Object
- #float(name, attributes = {}) ⇒ Object
- #input(name, klass, attributes) ⇒ Object
- #inputs ⇒ Object
- #integer(name, attributes = {}) ⇒ Object
- #object(name, klass, attributes = {}) ⇒ Object
- #required_inputs ⇒ Object
- #string(name, attributes = {}) ⇒ Object
Instance Method Details
#date(name, attributes = {}) ⇒ Object
40 41 42 |
# File 'lib/faire/attributes.rb', line 40 def date(name, attributes = {}) input(name, Date, attributes) end |
#defaults ⇒ Object
11 12 13 |
# File 'lib/faire/attributes.rb', line 11 def defaults { nullify_blank: true, required: true }.freeze end |
#float(name, attributes = {}) ⇒ Object
36 37 38 |
# File 'lib/faire/attributes.rb', line 36 def float(name, attributes = {}) input(name, Float, attributes) end |
#input(name, klass, attributes) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/faire/attributes.rb', line 25 def input(name, klass, attributes) attrs = defaults.merge(attributes) self.inputs << Input.new(name, String, attrs) self.attribute(name, klass, attrs) end |
#inputs ⇒ Object
7 8 9 |
# File 'lib/faire/attributes.rb', line 7 def inputs @inputs ||= [] end |
#integer(name, attributes = {}) ⇒ Object
32 33 34 |
# File 'lib/faire/attributes.rb', line 32 def integer(name, attributes = {}) input(name, Integer, attributes) end |
#object(name, klass, attributes = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/faire/attributes.rb', line 19 def object(name, klass, attributes = {}) klass.include(Virtus.model) input(name, klass, attributes) end |
#required_inputs ⇒ Object
3 4 5 |
# File 'lib/faire/attributes.rb', line 3 def required_inputs inputs.select(&:required?) end |
#string(name, attributes = {}) ⇒ Object
15 16 17 |
# File 'lib/faire/attributes.rb', line 15 def string(name, attributes = {}) input(name, String, attributes) end |