Class: YamlMaster
- Inherits:
-
Object
- Object
- YamlMaster
- Defined in:
- lib/yaml_master.rb,
lib/yaml_master/version.rb
Defined Under Namespace
Classes: EmbeddedMethods, KeyFetchError, PropertyParseError
Constant Summary collapse
- VERSION =
"0.4.2"
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
- #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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/yaml_master.rb', line 22 def initialize(io_or_filename, property_strings = []) parse_properties(property_strings) = EmbeddedMethods.new(self).get_binding data = if io_or_filename.is_a?(IO) ERB.new(io_or_filename.read).result() else @master_path = File.(io_or_filename) ERB.new(File.read(io_or_filename)).result() end @master = YAML.load(data) raise "yaml_master key is necessary on toplevel" unless @master["yaml_master"] raise "data key is necessary on toplevel" unless @master["data"] end |
Instance Attribute Details
#master ⇒ Object (readonly)
Returns the value of attribute master.
20 21 22 |
# File 'lib/yaml_master.rb', line 20 def master @master end |
#master_path ⇒ Object (readonly)
Returns the value of attribute master_path.
20 21 22 |
# File 'lib/yaml_master.rb', line 20 def master_path @master_path end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
20 21 22 |
# File 'lib/yaml_master.rb', line 20 def properties @properties end |
Instance Method Details
#generate(key, output = nil, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yaml_master.rb', line 39 def generate(key, output = nil, = {}) puts "gen: #{output}" if [:verbose] yaml = YAML.dump(fetch_data_from_master(key)) return yaml unless output File.open(output, 'w') do |f| f.write(yaml) end end |
#generate_all(options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/yaml_master.rb', line 50 def generate_all( = {}) @master["yaml_master"].each do |key, output| generate(key, output, ) end end |