conventional_models 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +37 -2
- data/features/multiple_databases.feature +0 -1
- data/lib/conventional_models/version.rb +1 -1
- data/lib/conventional_models.rb +6 -3
- metadata +2 -2
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
|
-
==
|
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" => {
|
data/lib/conventional_models.rb
CHANGED
@@ -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
|
-
|
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
|
-
@@
|
33
|
+
@@model_code.join("\n")
|
31
34
|
end
|
32
35
|
|
33
36
|
def self.model_code_for(table)
|