Class: TinyAdmin::Field
- Inherits:
-
Object
- Object
- TinyAdmin::Field
- Defined in:
- lib/tiny_admin/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_call_option(target) ⇒ Object
-
#initialize(name:, title:, type:, options: {}) ⇒ Field
constructor
A new instance of Field.
- #translate_value(value) ⇒ Object
Constructor Details
#initialize(name:, title:, type:, options: {}) ⇒ Field
Returns a new instance of Field.
7 8 9 10 11 12 |
# File 'lib/tiny_admin/field.rb', line 7 def initialize(name:, title:, type:, options: {}) @type = type @name = name @title = title @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/tiny_admin/field.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/tiny_admin/field.rb', line 5 def @options end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/tiny_admin/field.rb', line 5 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/tiny_admin/field.rb', line 5 def type @type end |
Class Method Details
.create_field(name:, title: nil, type: nil, options: {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/tiny_admin/field.rb', line 33 def create_field(name:, title: nil, type: nil, options: {}) field_name = name.to_s field_title = field_name.respond_to?(:humanize) ? field_name.humanize : field_name.tr('_', ' ').capitalize new(name: field_name, title: title || field_title, type: type || :string, options: || {}) end |
Instance Method Details
#apply_call_option(target) ⇒ Object
14 15 16 17 |
# File 'lib/tiny_admin/field.rb', line 14 def apply_call_option(target) = ([:call] || '').split(',').map(&:strip) .inject(target) { |result, msg| result&.send(msg) } if .any? end |
#translate_value(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tiny_admin/field.rb', line 19 def translate_value(value) if && [:method] method, *args = [:method].split(',').map(&:strip) if [:converter] Object.const_get([:converter]).send(method, value, options: args || []) else TinyAdmin.settings.helper_class.send(method, value, options: args || []) end else value&.to_s end end |