Class: ModulePlus::ConfigDef

Inherits:
Object
  • Object
show all
Defined in:
lib/module_plus/config_convention.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, path, attributes = {}) ⇒ ConfigDef

Returns a new instance of ConfigDef.



134
135
136
137
138
139
140
141
# File 'lib/module_plus/config_convention.rb', line 134

def initialize(key, path, attributes = {})
  @key  = key.to_s
  @path = path
  @desc = attributes[:desc] || ""
  @type = _type(attributes[:type])
  @type_strict = _type_strict(@type)
  @sample = attributes[:sample] || _sample(@type)
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



133
134
135
# File 'lib/module_plus/config_convention.rb', line 133

def desc
  @desc
end

#keyObject (readonly)

Returns the value of attribute key.



133
134
135
# File 'lib/module_plus/config_convention.rb', line 133

def key
  @key
end

#pathObject (readonly)

Returns the value of attribute path.



133
134
135
# File 'lib/module_plus/config_convention.rb', line 133

def path
  @path
end

#sampleObject (readonly)

Returns the value of attribute sample.



133
134
135
# File 'lib/module_plus/config_convention.rb', line 133

def sample
  @sample
end

#typeObject (readonly)

Returns the value of attribute type.



133
134
135
# File 'lib/module_plus/config_convention.rb', line 133

def type
  @type
end

Instance Method Details

#fieldObject



143
144
145
# File 'lib/module_plus/config_convention.rb', line 143

def field
  "#{@path.join(".")}.#{@key}"
end

#value(v) ⇒ Object



147
148
149
150
# File 'lib/module_plus/config_convention.rb', line 147

def value(v)
  raise new NotPermitedValueType.new("#{path}.#{@key}: #{v} is NOT Matched Type for #{@type}") unless @type_strict.call(v)
  v
end