Module: ConventionalModels

Defined in:
lib/conventional_models/version.rb,
lib/conventional_models.rb,
lib/conventional_models/cli.rb,
lib/conventional_models/table.rb,
lib/conventional_models/column.rb,
lib/conventional_models/config.rb,
lib/conventional_models/options.rb,
lib/conventional_models/database.rb

Overview

:nodoc:

Defined Under Namespace

Modules: VERSION Classes: CLI, Column, Config, Database, Options, Table

Constant Summary collapse

@@database =
nil
@@model_code =
[]

Class Method Summary collapse

Class Method Details

.configure(config = nil, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/conventional_models.rb', line 19

def self.configure(config=nil, &block)
  @@config = Config.new(&block)
  @@database = Database.new(@@config)
  code = @@database.code
  run_code code 
  @@model_code << code
end

.configure_active_record(config = 'config/database.yml', environment = 'development') ⇒ Object



45
46
47
48
49
# File 'lib/conventional_models.rb', line 45

def self.configure_active_record(config='config/database.yml', environment='development')
  config = YAML::load(IO.read(config))
  ActiveRecord::Base.configurations = config
  ActiveRecord::Base.establish_connection(config[environment])
end

.model_codeObject



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

def self.model_code
  @@model_code.join("\n")
end

.model_code_for(table) ⇒ Object



35
36
37
# File 'lib/conventional_models.rb', line 35

def self.model_code_for(table)
  @@database.code_for(table)
end

.run_code(code) ⇒ Object



27
28
29
# File 'lib/conventional_models.rb', line 27

def self.run_code(code)
  eval code
end

.run_console!Object



39
40
41
42
43
# File 'lib/conventional_models.rb', line 39

def self.run_console!
  configure_active_record
  configure
  IRB.start
end