Class: Workarea::Configuration::Administrable::Field
- Inherits:
-
Object
- Object
- Workarea::Configuration::Administrable::Field
- Defined in:
- lib/workarea/configuration/administrable/field.rb
Defined Under Namespace
Classes: Invalid
Instance Attribute Summary collapse
-
#fieldset ⇒ Object
readonly
Returns the value of attribute fieldset.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #allow_blank? ⇒ Boolean
- #encrypted? ⇒ Boolean
- #id ⇒ Object
-
#initialize(name, type:, fieldset: nil, **options) ⇒ Field
constructor
A new instance of Field.
- #key ⇒ Object
- #merge!(options = {}) ⇒ Object
- #overridden? ⇒ Boolean
- #type_class ⇒ Object
- #validate! ⇒ Object
- #values ⇒ Object
- #values_type_class ⇒ Object
Constructor Details
#initialize(name, type:, fieldset: nil, **options) ⇒ Field
Returns a new instance of Field.
10 11 12 13 14 15 |
# File 'lib/workarea/configuration/administrable/field.rb', line 10 def initialize(name, type:, fieldset: nil, **) @name = name @type = type.to_s.underscore.to_sym @fieldset = fieldset @options = OpenStruct.new() end |
Instance Attribute Details
#fieldset ⇒ Object (readonly)
Returns the value of attribute fieldset.
7 8 9 |
# File 'lib/workarea/configuration/administrable/field.rb', line 7 def fieldset @fieldset end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/workarea/configuration/administrable/field.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/workarea/configuration/administrable/field.rb', line 7 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/workarea/configuration/administrable/field.rb', line 7 def type @type end |
Instance Method Details
#allow_blank? ⇒ Boolean
55 56 57 |
# File 'lib/workarea/configuration/administrable/field.rb', line 55 def allow_blank? !!@options.allow_blank end |
#encrypted? ⇒ Boolean
45 46 47 |
# File 'lib/workarea/configuration/administrable/field.rb', line 45 def encrypted? !!encrypted end |
#id ⇒ Object
17 18 19 |
# File 'lib/workarea/configuration/administrable/field.rb', line 17 def id @id ||= (.id || name.to_s.systemize).to_sym end |
#key ⇒ Object
21 22 23 |
# File 'lib/workarea/configuration/administrable/field.rb', line 21 def key @key ||= fieldset&.namespaced? ? :"#{fieldset.id}_#{id}" : id end |
#merge!(options = {}) ⇒ Object
59 60 61 |
# File 'lib/workarea/configuration/administrable/field.rb', line 59 def merge!( = {}) @options = OpenStruct.new(.to_h.merge()) end |
#overridden? ⇒ Boolean
41 42 43 |
# File 'lib/workarea/configuration/administrable/field.rb', line 41 def overridden? Workarea.config.key?(key) end |
#type_class ⇒ Object
25 26 27 |
# File 'lib/workarea/configuration/administrable/field.rb', line 25 def type_class Workarea.config.configurable_field_types[type]&.constantize end |
#validate! ⇒ Object
49 50 51 52 53 |
# File 'lib/workarea/configuration/administrable/field.rb', line 49 def validate! validate_id validate_type self end |
#values ⇒ Object
29 30 31 32 |
# File 'lib/workarea/configuration/administrable/field.rb', line 29 def values return .values unless .values.respond_to?(:call) .values.call end |