Class: Convergence::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/convergence/dsl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



4
5
6
# File 'lib/convergence/dsl.rb', line 4

def initialize
  @tables = {}
end

Instance Attribute Details

#current_dir_pathObject

Returns the value of attribute current_dir_path.



2
3
4
# File 'lib/convergence/dsl.rb', line 2

def current_dir_path
  @current_dir_path
end

#tablesObject

Returns the value of attribute tables.



2
3
4
# File 'lib/convergence/dsl.rb', line 2

def tables
  @tables
end

Class Method Details

.parse(code, current_dir_path) ⇒ Object



20
21
22
23
24
25
# File 'lib/convergence/dsl.rb', line 20

def self.parse(code, current_dir_path)
  parser = new
  parser.current_dir_path = current_dir_path
  parser.instance_eval(code)
  parser.tables
end

Instance Method Details

#create_table(table_name, options = {}, &block) ⇒ Object



8
9
10
11
12
13
# File 'lib/convergence/dsl.rb', line 8

def create_table(table_name, options = {}, &block)
  table = Convergence::Table.new(table_name.to_s, options)
  block.call(table)
  @tables[table_name.to_s] = table
  table
end

#include(path) ⇒ Object



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

def include(path)
  next_dir_path = File.dirname("#{@current_dir_path}/#{path}")
  @tables.merge!(Convergence::DSL.parse(File.open("#{current_dir_path}/#{path}").read, next_dir_path))
end