Class: VCAP::Config
- Inherits:
-
Object
- Object
- VCAP::Config
- Defined in:
- lib/vcap/config.rb
Class Attribute Summary collapse
-
.schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
- .define_schema(&blk) ⇒ Object
- .from_file(filename, symbolize_keys = true) ⇒ Object
- .to_file(config, out_filename) ⇒ Object
Class Attribute Details
.schema ⇒ Object (readonly)
Returns the value of attribute schema.
10 11 12 |
# File 'lib/vcap/config.rb', line 10 def schema @schema end |
Class Method Details
.define_schema(&blk) ⇒ Object
12 13 14 |
# File 'lib/vcap/config.rb', line 12 def define_schema(&blk) @schema = Membrane::SchemaParser.parse(&blk) end |
.from_file(filename, symbolize_keys = true) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/vcap/config.rb', line 16 def from_file(filename, symbolize_keys=true) config = YAML.load_file(filename) config = VCAP.symbolize_keys(config) if symbolize_keys @schema.validate(config) config end |
.to_file(config, out_filename) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/vcap/config.rb', line 23 def to_file(config, out_filename) @schema.validate(config) File.open(out_filename, 'w+') do |f| YAML.dump(config, f) end end |