Class: Query

Inherits:
Object
  • Object
show all
Extended by:
Create, Insert
Defined in:
lib/yaml2sql.rb

Instance Method Summary collapse

Methods included from Create

build_create_query, create_insert_str, create_single_foreign, create_single_index, create_single_insert, create_tables

Methods included from Insert

create_insert_lambda, create_lambdas, create_select_id_lambda

Constructor Details

#initialize(yaml_path) ⇒ Query

Returns a new instance of Query.



77
78
79
80
81
82
# File 'lib/yaml2sql.rb', line 77

def initialize(yaml_path)
  yaml = YAML.load_file('schema.yaml')

  self.class.create_tables(yaml)
  create_methods(yaml)
end

Instance Method Details

#create_methods(yaml) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/yaml2sql.rb', line 84

def create_methods(yaml)
  lambdas = self.class.create_lambdas(yaml)

  lambdas.each do |x|
    insert_name =  ("insert_" + x[:name]).to_sym

    self.class.send(:define_method, insert_name) do |*args|
      x[:insert].call(*args)
    end

    select_name =  ("select_" + x[:name]).to_sym

    self.class.send(:define_method, select_name) do |val|
      x[:select].call(val)
    end
  end
end