Class: Lono::DSL
- Inherits:
-
Object
- Object
- Lono::DSL
- Defined in:
- lib/lono/dsl.rb
Instance Method Summary collapse
- #build ⇒ Object
- #evaluate ⇒ Object
-
#initialize(options = {}) ⇒ DSL
constructor
A new instance of DSL.
-
#load_subfolder ⇒ Object
load any templates defined in project/config/lono/*.
- #output(options = {}) ⇒ Object
- #run(options = {}) ⇒ Object
- #template(name, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DSL
Returns a new instance of DSL.
6 7 8 9 10 11 |
# File 'lib/lono/dsl.rb', line 6 def initialize(={}) @options = @path = [:config_path] || 'config/lono.rb' @templates = [] @results = {} end |
Instance Method Details
#build ⇒ Object
29 30 31 32 33 |
# File 'lib/lono/dsl.rb', line 29 def build @templates.each do |t| @results[t[:name]] = Template.new(t[:name], t[:block], @options).build end end |
#evaluate ⇒ Object
13 14 15 16 |
# File 'lib/lono/dsl.rb', line 13 def evaluate instance_eval(File.read(@path), @path) load_subfolder end |
#load_subfolder ⇒ Object
load any templates defined in project/config/lono/*
19 20 21 22 23 |
# File 'lib/lono/dsl.rb', line 19 def load_subfolder Dir.glob("#{File.dirname(@path)}/lono/*").each do |path| instance_eval(File.read(path), path) end end |
#output(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lono/dsl.rb', line 35 def output(={}) output_path = [:output_path] || 'output' FileUtils.rm_rf(output_path) if [:clean] FileUtils.mkdir(output_path) unless File.exist?(output_path) puts "Generating Cloud Formation templates:" if [:verbose] @results.each do |name,json| path = "#{output_path}/#{name}" puts " #{path}" if [:verbose] pretty_json = JSON.pretty_generate(JSON.parse(json)) File.open(path, 'w') {|f| f.write(pretty_json) } end end |
#run(options = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/lono/dsl.rb', line 48 def run(={}) evaluate build .empty? ? output : output() end |
#template(name, &block) ⇒ Object
25 26 27 |
# File 'lib/lono/dsl.rb', line 25 def template(name, &block) @templates << {:name => name, :block => block} end |