Module: PunterSqlite3

Defined in:
lib/punter/punter_sqlite3.rb

Class Method Summary collapse

Class Method Details

.generate_modelsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/punter/punter_sqlite3.rb', line 13

def self.generate_models
  tables = ActiveRecord::Base.connection.tables
  puts "tables found: #{tables}"
  tables.each do |table_name|
    $logger.debug "generating model for #{table_name}"
    variable = table_name.titleize.gsub(" ", "")
    klass = Class.new(ActiveRecord::Base)
    # ...maybe evaluate some code in the context of the new, anonymous class

    ## ...or define some methods
    #klass.send(:attribute, :name, String)
    # Finally, name that class!
    klass.send(:table_name=, table_name)
    MethodGenerator.add_method(table_name){return klass}
    ActiveRecord::Base.send(:const_set, variable, klass)
  end
  MethodGenerator.add_method("show_tables"){return tables}
end

.init(absolute_filepath) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/punter/punter_sqlite3.rb', line 5

def self.init(absolute_filepath)
  ActiveRecord::Base.establish_connection(
    :adapter => "sqlite3",
    :database  => absolute_filepath
  ) 
  generate_models
end