Class: ROM::Configurable::Setting Private
- Inherits:
-
Object
- Object
- ROM::Configurable::Setting
- Defined in:
- lib/rom/support/configurable/setting.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class represents a setting and is used internally.
Direct Known Subclasses
Defined Under Namespace
Classes: Nested
Constant Summary collapse
- OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[input default reader constructor cloneable settings].freeze
- DEFAULT_CONSTRUCTOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
-> v { v }.freeze
- CLONEABLE_VALUE_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[Array, Hash, Set, Config].freeze
Instance Attribute Summary collapse
- #default ⇒ Object readonly private
- #input ⇒ Object readonly private
- #name ⇒ Object readonly private
- #options ⇒ Object readonly private
- #writer_name ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #cloneable? ⇒ Boolean private
- #constructor ⇒ Object private
- #evaluated? ⇒ Boolean private
-
#initialize(name, input: Undefined, default: Undefined, **options) ⇒ Setting
constructor
private
A new instance of Setting.
- #input_defined? ⇒ Boolean private
- #nested(settings) ⇒ Object private
- #pristine ⇒ Object private
- #reader? ⇒ Boolean private
- #value ⇒ Object private
- #with(new_opts) ⇒ Object private
- #writer?(meth) ⇒ Boolean private
Constructor Details
#initialize(name, input: Undefined, default: Undefined, **options) ⇒ Setting
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Setting.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rom/support/configurable/setting.rb', line 59 def initialize(name, input: Undefined, default: Undefined, **) @name = name @writer_name = :"#{name}=" @options = # Setting collections (see `Settings`) are shared between the configurable class # and its `config` object, so for cloneable individual settings, we duplicate # their _values_ as early as possible to ensure no impact from unintended mutation @input = input @default = default if cloneable? @input = input.dup @default = default.dup end evaluate if input_defined? end |
Instance Attribute Details
#default ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/rom/support/configurable/setting.rb', line 31 def default @default end |
#input ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/rom/support/configurable/setting.rb', line 28 def input @input end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/rom/support/configurable/setting.rb', line 22 def name @name end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/rom/support/configurable/setting.rb', line 34 def @options end |
#writer_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/rom/support/configurable/setting.rb', line 25 def writer_name @writer_name end |
Class Method Details
.cloneable_value?(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/rom/support/configurable/setting.rb', line 54 def self.cloneable_value?(value) CLONEABLE_VALUE_TYPES.any? { |type| value.is_a?(type) } end |
Instance Method Details
#cloneable? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rom/support/configurable/setting.rb', line 123 def cloneable? if .key?(:cloneable) # Return cloneable option if explicitly set [:cloneable] else # Otherwise, infer cloneable from any of the input, default, or value Setting.cloneable_value?(input) || Setting.cloneable_value?(default) || ( evaluated? && Setting.cloneable_value?(value) ) end end |
#constructor ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 |
# File 'lib/rom/support/configurable/setting.rb', line 108 def constructor [:constructor] || DEFAULT_CONSTRUCTOR end |
#evaluated? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'lib/rom/support/configurable/setting.rb', line 88 def evaluated? instance_variable_defined?(:@value) end |
#input_defined? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/rom/support/configurable/setting.rb', line 78 def input_defined? !input.equal?(Undefined) end |
#nested(settings) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 |
# File 'lib/rom/support/configurable/setting.rb', line 93 def nested(settings) Nested.new(name, input: settings, **) end |
#pristine ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 |
# File 'lib/rom/support/configurable/setting.rb', line 98 def pristine with(input: Undefined) end |
#reader? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
113 114 115 |
# File 'lib/rom/support/configurable/setting.rb', line 113 def reader? [:reader].equal?(true) end |
#value ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 |
# File 'lib/rom/support/configurable/setting.rb', line 83 def value @value ||= evaluate end |
#with(new_opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 |
# File 'lib/rom/support/configurable/setting.rb', line 103 def with(new_opts) self.class.new(name, input: input, default: default, **, **new_opts) end |
#writer?(meth) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 |
# File 'lib/rom/support/configurable/setting.rb', line 118 def writer?(meth) writer_name.equal?(meth) end |