Class: Lustr::DSL

Inherits:
BlankSlate show all
Defined in:
lib/lustr/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parse_context, eval_context) ⇒ DSL

Returns a new instance of DSL.



28
29
30
31
32
# File 'lib/lustr/dsl.rb', line 28

def initialize(parse_context, eval_context)
  @parse_context=parse_context
  @eval_context=eval_context
  @involved=[]
end

Class Method Details

.add_dsl_method(*symbols) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/lustr/dsl.rb', line 18

def self.add_dsl_method(*symbols)
  symbols.each do |sym|
    class_eval "      def \#{sym}(options={})\n        @parse_context.add_builder(:\#{sym}, options) { yield if block_given? }\n      end\n"
  end
end

Instance Method Details

#gadget(options) ⇒ Object



41
42
43
44
45
# File 'lib/lustr/dsl.rb', line 41

def gadget(options)
  builder=GadgetBuilder.new(options)
  @parse_context.attach_builder(builder, options[:name]) { yield if block_given? }
  Lustr.add_dsl_handler(options[:name].to_sym, builder)
end

#involve(path) ⇒ Object



34
35
36
37
38
39
# File 'lib/lustr/dsl.rb', line 34

def involve(path)
  if !@involved.include?(path)
    @involved << path
    self.instance_eval(File.new(path).read, path) 
  end
end

#is_runtime?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/lustr/dsl.rb', line 47

def is_runtime?
  @eval_context.is_runtime?
end