Class: Fino::Settings::Select::OptionRegistry
- Inherits:
-
Object
- Object
- Fino::Settings::Select::OptionRegistry
- Defined in:
- lib/fino/settings/select.rb
Constant Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ OptionRegistry
constructor
A new instance of OptionRegistry.
- #option(value, *path) ⇒ Object
- #options(*path) ⇒ Object
- #refresh!(*path) ⇒ Object
- #refreshable?(*path) ⇒ Boolean
- #register(builder, path) ⇒ Object
Constructor Details
#initialize ⇒ OptionRegistry
Returns a new instance of OptionRegistry.
23 24 25 26 27 |
# File 'lib/fino/settings/select.rb', line 23 def initialize @options = {} @indexed_options = {} @builders = {} end |
Instance Method Details
#option(value, *path) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/fino/settings/select.rb', line 38 def option(value, *path) resolve(path) @indexed_options.dig(*path.compact.map(&:to_s)).fetch(value) do raise UnknownOption, "Unknown option: #{value} for setting: #{path.compact.join('.')}" end end |
#options(*path) ⇒ Object
33 34 35 36 |
# File 'lib/fino/settings/select.rb', line 33 def (*path) resolve(path) @options.dig(*path.compact.map(&:to_s)) end |
#refresh!(*path) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/fino/settings/select.rb', line 50 def refresh!(*path) string_path = path.compact.map(&:to_s) builder = @builders.dig(*string_path) return unless builder.respond_to?(:call) resolve(path, force: true) @options.dig(*string_path) end |
#refreshable?(*path) ⇒ Boolean
45 46 47 48 |
# File 'lib/fino/settings/select.rb', line 45 def refreshable?(*path) builder = @builders.dig(*path.compact.map(&:to_s)) builder.respond_to?(:call) end |
#register(builder, path) ⇒ Object
29 30 31 |
# File 'lib/fino/settings/select.rb', line 29 def register(builder, path) @builders.deep_set(builder, *path) end |