Class: Configurations::Maps::Types
- Inherits:
-
Object
- Object
- Configurations::Maps::Types
- Defined in:
- lib/configurations/maps/types.rb
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
- #add(type, properties) ⇒ Object
- #add_entry(property, type, subtree) ⇒ Object
-
#initialize(reader = Readers::Tolerant.new) ⇒ Types
constructor
A new instance of Types.
- #test!(path, value) ⇒ Object
Constructor Details
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
4 5 6 |
# File 'lib/configurations/maps/types.rb', line 4 def map @map end |
Instance Method Details
#add(type, properties) ⇒ Object
22 23 24 25 26 |
# File 'lib/configurations/maps/types.rb', line 22 def add(type, properties) properties.each do |property| add_entry(property, type, @map) end end |
#add_entry(property, type, subtree) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/configurations/maps/types.rb', line 39 def add_entry(property, type, subtree) if property.is_a?(Hash) property.each do |key, val| subtree[key] = add_entry(val, type, subtree.fetch(key, {})) end elsif property.is_a?(Array) property.each do |val| add_entry(val, type, subtree) end else subtree[property] = Entry.new(type) end subtree end |
#test!(path, value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/configurations/maps/types.rb', line 28 def test!(path, value) entry = @reader.read(@map, path) return unless entry fail( ConfigurationError, "#{path.print} must be configured with #{entry.type} (got #{value})", caller ) unless entry.valid?(value) end |