Class: YamlMaster
- Inherits:
-
Object
- Object
- YamlMaster
- Defined in:
- lib/yaml_master.rb,
lib/yaml_master/version.rb
Defined Under Namespace
Classes: EmbeddedMethods, KeyFetchError
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#master ⇒ Object
readonly
Returns the value of attribute master.
-
#master_path ⇒ Object
readonly
Returns the value of attribute master_path.
Instance Method Summary collapse
- #generate(key, output = nil, options = {}) ⇒ Object
- #generate_all(options = {}) ⇒ Object
-
#initialize(io_or_filename) ⇒ YamlMaster
constructor
A new instance of YamlMaster.
Constructor Details
#initialize(io_or_filename) ⇒ YamlMaster
Returns a new instance of YamlMaster.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/yaml_master.rb', line 21 def initialize(io_or_filename) = EmbeddedMethods.new(self) = .instance_eval { 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.
19 20 21 |
# File 'lib/yaml_master.rb', line 19 def master @master end |
#master_path ⇒ Object (readonly)
Returns the value of attribute master_path.
19 20 21 |
# File 'lib/yaml_master.rb', line 19 def master_path @master_path end |
Instance Method Details
#generate(key, output = nil, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/yaml_master.rb', line 37 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
48 49 50 51 52 |
# File 'lib/yaml_master.rb', line 48 def generate_all( = {}) @master["yaml_master"].each do |key, output| generate(key, output, ) end end |