conventional_models 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -76,7 +76,6 @@ You can use this from rake as follows:
76
76
  # Confiigure active_record as you would normally
77
77
 
78
78
  task :console do
79
- require 'irb'
80
79
  require 'conventional_models'
81
80
  ConventionalModels.configure do
82
81
  primary_key_name "Id"
@@ -91,9 +90,45 @@ You can use this from rake as follows:
91
90
  I use this for data migrations or quick scripting tasks on databases that don't follow rails
92
91
  conventions.
93
92
 
94
- == TODO
93
+ == Multiple databases
95
94
 
95
+ Given a table called pages in both development.sqlite and test.sqlite:
96
96
 
97
+ require 'rubygems'
98
+ require 'active_record'
99
+ require 'conventional_models'
100
+ config = {
101
+ "development" => {
102
+ "database" => 'development.sqlite',
103
+ "adapter" => 'sqlite3'
104
+ },
105
+ "test" => {
106
+ "database" => 'test.sqlite',
107
+ "adapter" => 'sqlite3'
108
+ }
109
+ }
110
+ ConventionalModels.configure do
111
+ connection config["development"]
112
+ module_name "Development"
113
+ end
114
+ ConventionalModels.configure do
115
+ connection config["test"]
116
+ module_name "Test"
117
+ end
118
+ puts ConventionalModels.model_code
119
+ # => class ::Development::Page < Development::Base
120
+ # =>
121
+ # => end
122
+ # => class ::Test::Page < Test::Base
123
+ # =>
124
+ # => end
125
+ Development::Page.create!
126
+ Development::Page.create!
127
+ Test::Page.create!
128
+ puts "Number of development records: #{Development::Page.count}"
129
+ # => 2
130
+ puts "Number of production records: #{Test::Page.count}"
131
+ # => 1
97
132
 
98
133
  == Note on Patches/Pull Requests
99
134
 
@@ -11,7 +11,6 @@ Feature: Multiple database connection
11
11
  $:.unshift("../../lib")
12
12
  require 'rubygems'
13
13
  require 'active_record'
14
- ActiveRecord::Base.establish_connection(:database => 'development.sqlite', :adapter => 'sqlite3')
15
14
  require 'conventional_models'
16
15
  config = {
17
16
  "development" => {
@@ -2,7 +2,7 @@ module ConventionalModels #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- BUILD = 1
5
+ BUILD = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, BUILD].join('.')
8
8
  end
@@ -10,16 +10,19 @@ require 'conventional_models/active_record_base_model_for'
10
10
  require 'conventional_models/options'
11
11
  require 'conventional_models/option_parser'
12
12
  require 'conventional_models/cli'
13
- require 'irb';
13
+ require 'irb'
14
14
  require 'irb/completion'
15
15
 
16
16
  module ConventionalModels
17
17
  @@database = nil
18
+ @@model_code = []
18
19
 
19
20
  def self.configure(config=nil, &block)
20
21
  @@config = Config.new(&block)
21
22
  @@database = Database.new(@@config)
22
- run_code @@database.code
23
+ code = @@database.code
24
+ run_code code
25
+ @@model_code << code
23
26
  end
24
27
 
25
28
  def self.run_code(code)
@@ -27,7 +30,7 @@ module ConventionalModels
27
30
  end
28
31
 
29
32
  def self.model_code
30
- @@database.code
33
+ @@model_code.join("\n")
31
34
  end
32
35
 
33
36
  def self.model_code_for(table)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Steve Hodgkiss