Class: YamlMaster
- Inherits:
-
Object
- Object
- YamlMaster
- Defined in:
- lib/yaml_master.rb,
lib/yaml_master/version.rb
Defined Under Namespace
Modules: PropertyParser Classes: Context, KeyFetchError, YAMLTreeBuilder
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#master ⇒ Object
readonly
Returns the value of attribute master.
-
#master_path ⇒ Object
readonly
Returns the value of attribute master_path.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #dump(output = nil, options = {}) ⇒ Object
- #generate(key, output = nil, options = {}) ⇒ Object
- #generate_all(options = {}) ⇒ Object
-
#initialize(io_or_filename, property_strings = []) ⇒ YamlMaster
constructor
A new instance of YamlMaster.
Constructor Details
#initialize(io_or_filename, property_strings = []) ⇒ YamlMaster
Returns a new instance of YamlMaster.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yaml_master.rb', line 17 def initialize(io_or_filename, property_strings = []) case io_or_filename when String @master_path = Pathname(io_or_filename). when File @master_path = Pathname(io_or_filename.absolute_path) end @properties = PropertyParser.parse_properties(property_strings) yaml = Context.new(master_path, @properties).render_master parser = YAML::Parser.new parser.handler = YamlMaster::YAMLTreeBuilder.new(@master_path, @properties, parser) @tree = parser.parse(yaml).handler.root @master = @tree.to_ruby[0] end |
Instance Attribute Details
#master ⇒ Object (readonly)
Returns the value of attribute master.
15 16 17 |
# File 'lib/yaml_master.rb', line 15 def master @master end |
#master_path ⇒ Object (readonly)
Returns the value of attribute master_path.
15 16 17 |
# File 'lib/yaml_master.rb', line 15 def master_path @master_path end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
15 16 17 |
# File 'lib/yaml_master.rb', line 15 def properties @properties end |
Instance Method Details
#dump(output = nil, options = {}) ⇒ Object
34 35 36 37 |
# File 'lib/yaml_master.rb', line 34 def dump(output = nil, = {}) yaml = @tree.to_yaml write_to_output(yaml, output, [:verbose]) end |
#generate(key, output = nil, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/yaml_master.rb', line 39 def generate(key, output = nil, = {}) raise "data key is necessary on toplevel" unless @master["data"] yaml = YAML.dump(fetch_data_from_master(key)) write_to_output(yaml, output, [:verbose]) end |
#generate_all(options = {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/yaml_master.rb', line 45 def generate_all( = {}) raise "yaml_master key is necessary on toplevel" unless @master["yaml_master"] raise "data key is necessary on toplevel" unless @master["data"] @master["yaml_master"].each do |key, output| generate(key, output, ) end end |