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.



6
7
8
# File 'lib/convergence/dsl.rb', line 6

def initialize
  @tables = {}
end

Instance Attribute Details

#current_dir_pathObject

Returns the value of attribute current_dir_path.



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

def current_dir_path
  @current_dir_path
end

#tablesObject

Returns the value of attribute tables.



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

def tables
  @tables
end

Class Method Details

.parse(code, current_dir_path) ⇒ Object



22
23
24
25
26
27
# File 'lib/convergence/dsl.rb', line 22

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



10
11
12
13
14
15
# File 'lib/convergence/dsl.rb', line 10

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



17
18
19
20
# File 'lib/convergence/dsl.rb', line 17

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