Class: ZenAdmin::Core::Field
- Inherits:
-
Object
- Object
- ZenAdmin::Core::Field
- Defined in:
- lib/zen_admin/core/field.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#required ⇒ Object
Returns the value of attribute required.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, type: :string, options: {}, required: false, condition: nil, label: nil) ⇒ Field
constructor
A new instance of Field.
- #label ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, type: :string, options: {}, required: false, condition: nil, label: nil) ⇒ Field
6 7 8 9 10 11 12 13 |
# File 'lib/zen_admin/core/field.rb', line 6 def initialize(name, type: :string, options: {}, required: false, condition: nil, label: nil) @name = name @type = type = [:label] = label if label @required = required @condition = condition end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
4 5 6 |
# File 'lib/zen_admin/core/field.rb', line 4 def condition @condition end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/zen_admin/core/field.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/zen_admin/core/field.rb', line 4 def end |
#required ⇒ Object
Returns the value of attribute required.
4 5 6 |
# File 'lib/zen_admin/core/field.rb', line 4 def required @required end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/zen_admin/core/field.rb', line 4 def type @type end |
Instance Method Details
#label ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/zen_admin/core/field.rb', line 15 def label val = [:label] if val.is_a?(Symbol) I18n.t(val) else val || @name.to_s.humanize end end |
#to_h ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/zen_admin/core/field.rb', line 24 def to_h { name: @name.to_s, type: @type.to_s, required: @required, options: [] } end |