Class: StandardConfig::Schema::ScopeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/standard_config/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ScopeBuilder

Returns a new instance of ScopeBuilder.



76
77
78
79
# File 'lib/standard_config/schema.rb', line 76

def initialize(name)
  @name = name.to_sym
  @fields = Concurrent::Map.new
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



74
75
76
# File 'lib/standard_config/schema.rb', line 74

def fields
  @fields
end

#nameObject (readonly)

Returns the value of attribute name.



74
75
76
# File 'lib/standard_config/schema.rb', line 74

def name
  @name
end

Instance Method Details

#field(name, type: :string, default: nil, readonly: false) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/standard_config/schema.rb', line 81

def field(name, type: :string, default: nil, readonly: false)
  key = name.to_sym
  if @fields.key?(key)
    Kernel.warn("[StandardId::Configuration] Redefining field '#{key}' in scope '#{@name}'. Last definition wins.")
  end
  @fields[key] = FieldDefinition.new(name, type: type, default: default, readonly: readonly)
end