Module: Ytrbium::DSL

Defined in:
lib/ytrbium/dsl.rb

Instance Method Summary collapse

Instance Method Details

#call(options = {}) ⇒ Object



16
17
18
# File 'lib/ytrbium/dsl.rb', line 16

def call(options = {})
  YAML.safe_load expand(binding)
end

#engine(input = nil, options = {}) ⇒ Object



7
8
9
10
# File 'lib/ytrbium/dsl.rb', line 7

def engine(input = nil, options = {})
  @engine = nil if input
  @engine ||= Engine.new(input, options)
end

#expand(binding = nil) ⇒ Object



12
13
14
# File 'lib/ytrbium/dsl.rb', line 12

def expand(binding = nil)
  engine.expand(binding)
end

#expand_path(name) ⇒ Object



20
21
22
# File 'lib/ytrbium/dsl.rb', line 20

def expand_path(name)
  file_resolver.expand_path name
end

#file_resolverObject



3
4
5
# File 'lib/ytrbium/dsl.rb', line 3

def file_resolver
  @file_resolver ||= FileResolver.new
end

#import(name, as: nil, **options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ytrbium/dsl.rb', line 24

def import(name, as: nil, **options)
  mod = Ytrbium.dsl
  file_resolver.load(name) do |io, filename|
    mod.engine(io.read, filename: filename, module: mod)
  end
  if as
    define_method(as) { mod }
  else
    mod.call(options || {})
  end
end