Class: TinyAdmin::Field
- Inherits:
-
Object
- Object
- TinyAdmin::Field
- Extended by:
- Utils
- 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
Methods included from Utils
humanize, params_to_s, prepare_page, to_class
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
35 36 37 38 |
# File 'lib/tiny_admin/field.rb', line 35 def create_field(name:, title: nil, type: nil, options: {}) field_name = name.to_s new(name: field_name, title: title || humanize(field_name), 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 |