Class: FiForm::Item
- Inherits:
-
Struct
- Object
- Struct
- FiForm::Item
- Defined in:
- lib/fi_form/item.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#options ⇒ Object
Returns the value of attribute options.
-
#resource ⇒ Object
(also: #object)
readonly
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #add_items(items) ⇒ Object
- #as_json(*args) ⇒ Object
- #errors ⇒ Object
-
#initialize(*args) ⇒ Item
constructor
A new instance of Item.
- #input ⇒ Object
- #items ⇒ Object (also: #children)
- #last_child ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(*args) ⇒ Item
Returns a new instance of Item.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fi_form/item.rb', line 31 def initialize(*args) super @form = self..delete(:form) @resource = if self..key? :resource self..delete(:resource) else @form.resource end end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
29 30 31 |
# File 'lib/fi_form/item.rb', line 29 def field @field end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
29 30 31 |
# File 'lib/fi_form/item.rb', line 29 def form @form end |
#kind ⇒ Object
Returns the value of attribute kind
1 2 3 |
# File 'lib/fi_form/item.rb', line 1 def kind @kind end |
#options ⇒ Object
Returns the value of attribute options
1 2 3 |
# File 'lib/fi_form/item.rb', line 1 def end |
#resource ⇒ Object (readonly) Also known as: object
Returns the value of attribute resource.
29 30 31 |
# File 'lib/fi_form/item.rb', line 29 def resource @resource end |
Class Method Details
.build(kind, options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fi_form/item.rb', line 18 def self.build(kind, ) case kind when :input Input when :form Form else self end.new(kind, ) end |
Instance Method Details
#<<(item) ⇒ Object
63 64 65 66 |
# File 'lib/fi_form/item.rb', line 63 def <<(item) self.[:items] ||= [] self.[:items] << item end |
#add_items(items) ⇒ Object
68 69 70 |
# File 'lib/fi_form/item.rb', line 68 def add_items(items) self.[:items] += items end |
#as_json(*args) ⇒ Object
76 77 78 |
# File 'lib/fi_form/item.rb', line 76 def as_json(*args) super(except: :resource) end |
#errors ⇒ Object
42 43 44 |
# File 'lib/fi_form/item.rb', line 42 def errors self..fetch(:errors) end |
#input ⇒ Object
59 60 61 |
# File 'lib/fi_form/item.rb', line 59 def input self.&.dig(:input) end |
#items ⇒ Object Also known as: children
46 47 48 |
# File 'lib/fi_form/item.rb', line 46 def items self.&.dig(:items) || [] end |
#last_child ⇒ Object
72 73 74 |
# File 'lib/fi_form/item.rb', line 72 def last_child self.[:items].last end |
#value ⇒ Object
55 56 57 |
# File 'lib/fi_form/item.rb', line 55 def value self..fetch(:value) end |