Class: OpenDsl::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/open_dsl/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil, &blk) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
13
14
15
16
# File 'lib/open_dsl/builder.rb', line 8

def initialize(file = nil, &blk)
  if file
    build_from_file(file)
  elsif blk
    build_from_proc(blk)
  else
    raise "OpenDsl#new requires either a file to load or a block as an argument"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(const_name, *args, &blk) ⇒ Object (protected)



31
32
33
# File 'lib/open_dsl/builder.rb', line 31

def method_missing(const_name, *args, &blk)
  @context = Context.new(const_name, &blk)
end

Class Method Details

.build(file = nil, &blk) ⇒ Object



3
4
5
6
# File 'lib/open_dsl/builder.rb', line 3

def self.build(file = nil, &blk)
  builder = new(file, &blk)
  builder.context.toplevel_object
end

Instance Method Details

#contextObject



18
19
20
# File 'lib/open_dsl/builder.rb', line 18

def context
  @context
end