Class: StandardId::ConfigSchema::Config

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/standard_id/config_schema.rb

Overview

Top-level config: routes unqualified field reads/writes to the owning scope when the name is unique across scopes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__schema__Object

Returns the value of attribute __schema__.



171
172
173
# File 'lib/standard_id/config_schema.rb', line 171

def __schema__
  @__schema__
end

Instance Method Details

#[](key) ⇒ Object



184
185
186
187
188
189
# File 'lib/standard_id/config_schema.rb', line 184

def [](key)
  sym = key.to_sym
  return super if key?(sym) || __schema__.nil? || __schema__.scope?(sym)
  target = unique_scope_for(sym)
  target ? self[target][sym] : super
end

#[]=(key, value) ⇒ Object



191
192
193
194
195
196
197
198
# File 'lib/standard_id/config_schema.rb', line 191

def []=(key, value)
  sym = key.to_sym
  if __schema__ && !__schema__.scope?(sym) && !key?(sym) && (target = unique_scope_for(sym))
    self[target][sym] = value
  else
    super(sym, value)
  end
end

#register(scope_name, resolver) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/standard_id/config_schema.rb', line 173

def register(scope_name, resolver)
  sym = scope_name.to_sym
  unless __schema__&.scope?(sym)
    raise ArgumentError, "Unknown configuration scope: #{sym}. Valid scopes: #{__schema__&.scopes&.keys}"
  end
  self[sym].resolver = resolver
  self
end

#registered?(scope_name) ⇒ Boolean

Returns:

  • (Boolean)


182
# File 'lib/standard_id/config_schema.rb', line 182

def registered?(scope_name) = !!self[scope_name.to_sym]&.resolver

#write_raw(key, value) ⇒ Object

Bypass routing — used by the schema applier.



201
# File 'lib/standard_id/config_schema.rb', line 201

def write_raw(key, value) = RAW_SET.bind_call(self, key.to_sym, value)