Class: ROM::Configurable::Setting Private

Inherits:
Object
  • Object
show all
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

Nested

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

Class Method Summary collapse

Instance Method Summary collapse

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, **options)
  @name = name
  @writer_name = :"#{name}="
  @options = 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

#defaultObject (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

#inputObject (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

#nameObject (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

#optionsObject (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
  @options
end

#writer_nameObject (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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rom/support/configurable/setting.rb', line 123

def cloneable?
  if options.key?(:cloneable)
    # Return cloneable option if explicitly set
    options[: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

#constructorObject

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
  options[: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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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, **options)
end

#pristineObject

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.

Returns:

  • (Boolean)


113
114
115
# File 'lib/rom/support/configurable/setting.rb', line 113

def reader?
  options[:reader].equal?(true)
end

#valueObject

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, **options, **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.

Returns:

  • (Boolean)


118
119
120
# File 'lib/rom/support/configurable/setting.rb', line 118

def writer?(meth)
  writer_name.equal?(meth)
end