Class: Fino::Definition::Setting
- Inherits:
-
Object
- Object
- Fino::Definition::Setting
- Defined in:
- lib/fino/definition/setting.rb
Constant Summary collapse
- TYPE_CLASSES =
[ Fino::Settings::String, Fino::Settings::Integer, Fino::Settings::Float, Fino::Settings::Boolean, Fino::Settings::Select ].freeze
- SETTING_TYPE_TO_TYPE_CLASS_MAPPING =
TYPE_CLASSES.each_with_object({}) do |klass, hash| hash[klass.type_identifier] = klass end.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#section_definition ⇒ Object
readonly
Returns the value of attribute section_definition.
-
#setting_name ⇒ Object
readonly
Returns the value of attribute setting_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #default ⇒ Object
- #description ⇒ Object
- #deserialize(raw_value) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(type:, setting_name:, section_definition: nil, **options) ⇒ Setting
constructor
A new instance of Setting.
- #key ⇒ Object
- #path ⇒ Object
- #serialize(value) ⇒ Object
- #tags ⇒ Object
- #type_class ⇒ Object
Constructor Details
#initialize(type:, setting_name:, section_definition: nil, **options) ⇒ Setting
Returns a new instance of Setting.
18 19 20 21 22 23 |
# File 'lib/fino/definition/setting.rb', line 18 def initialize(type:, setting_name:, section_definition: nil, **) @setting_name = setting_name @section_definition = section_definition @type = type @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/fino/definition/setting.rb', line 16 def @options end |
#section_definition ⇒ Object (readonly)
Returns the value of attribute section_definition.
16 17 18 |
# File 'lib/fino/definition/setting.rb', line 16 def section_definition @section_definition end |
#setting_name ⇒ Object (readonly)
Returns the value of attribute setting_name.
16 17 18 |
# File 'lib/fino/definition/setting.rb', line 16 def setting_name @setting_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/fino/definition/setting.rb', line 16 def type @type end |
Instance Method Details
#default ⇒ Object
39 40 41 |
# File 'lib/fino/definition/setting.rb', line 39 def default defined?(@default) ? @default : @default = deserialize([:default]) end |
#description ⇒ Object
43 44 45 |
# File 'lib/fino/definition/setting.rb', line 43 def description defined?(@description) ? @description : @description = [:description] end |
#deserialize(raw_value) ⇒ Object
35 36 37 |
# File 'lib/fino/definition/setting.rb', line 35 def deserialize(raw_value) type_class.deserialize(self, raw_value) end |
#eql?(other) ⇒ Boolean Also known as: ==
59 60 61 |
# File 'lib/fino/definition/setting.rb', line 59 def eql?(other) self.class.eql?(other.class) && key == other.key end |
#hash ⇒ Object
64 65 66 |
# File 'lib/fino/definition/setting.rb', line 64 def hash key.hash end |
#key ⇒ Object
55 56 57 |
# File 'lib/fino/definition/setting.rb', line 55 def key @key ||= path.join("/") end |
#path ⇒ Object
51 52 53 |
# File 'lib/fino/definition/setting.rb', line 51 def path @path ||= [section_definition&.name, setting_name].compact end |
#serialize(value) ⇒ Object
31 32 33 |
# File 'lib/fino/definition/setting.rb', line 31 def serialize(value) type_class.serialize(self, value) end |
#tags ⇒ Object
47 48 49 |
# File 'lib/fino/definition/setting.rb', line 47 def defined?(@tags) ? @tags : @tags = [:tags] || [] end |
#type_class ⇒ Object
25 26 27 28 29 |
# File 'lib/fino/definition/setting.rb', line 25 def type_class @type_class ||= SETTING_TYPE_TO_TYPE_CLASS_MAPPING.fetch(type) do raise ArgumentError, "Unknown setting type #{type}" end end |