Class: Fino::Settings::Select::OptionRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/fino/settings/select.rb

Constant Summary collapse

UnknownOption =
Class.new(Fino::Error)

Instance Method Summary collapse

Constructor Details

#initializeOptionRegistry

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 options(*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

Returns:



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