class Dslimple::DSL
Public Class Methods
new(file, context = {})
click to toggle source
# File lib/dslimple/dsl.rb, line 5 def initialize(file, context = {}) @file = Pathname.new(file) @dir = @file.dirname @zones = [] @files = [] @context = context end
Public Instance Methods
evaluate(file)
click to toggle source
# File lib/dslimple/dsl.rb, line 30 def evaluate(file) @files << file.to_s instance_eval(File.read(file), file.to_s) rescue ScriptError => e raise Dslimple::DSL::Error, "#{e.class}: #{e.message}", cleanup_backtrace(e.backtrace) rescue StandardError => e raise Dslimple::DSL::Error, "#{e.class}: #{e.message}", cleanup_backtrace(e.backtrace) end
execute()
click to toggle source
# File lib/dslimple/dsl.rb, line 14 def execute evaluate(@file) end
require(path)
click to toggle source
# File lib/dslimple/dsl.rb, line 18 def require(path) if @dir.join(path).exist? evaluate(@dir.join(path)) elsif @dir.join("#{path}.rb").exist? evaluate(@dir.join("#{path}.rb")) elsif @dir.join("#{path}.zone").exist? evaluate(@dir.join("#{path}.zone")) else Kernel.require(path) end end
transform()
click to toggle source
# File lib/dslimple/dsl.rb, line 43 def transform @zones.map do |zone| Dslimple::Zone.new(zone.name).tap do |model| model.records = zone.records.map do |record| Dslimple::Record.new(record) end end end end
zone(name, &block)
click to toggle source
# File lib/dslimple/dsl.rb, line 39 def zone(name, &block) @zones << Dslimple::DSL::Zone.new(name, &block) end
Private Instance Methods
cleanup_backtrace(backtrace)
click to toggle source
# File lib/dslimple/dsl.rb, line 55 def cleanup_backtrace(backtrace) return backtrace if @context[:debug] backtrace.select do |bt| path = bt.split(':')[0..-3].join(':') @files.include?(path) end end