active_schema 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.autotest +1 -0
  2. data/.document +11 -0
  3. data/.gitignore +48 -0
  4. data/.rspec +3 -0
  5. data/Gemfile +21 -0
  6. data/Gemfile.lock +63 -0
  7. data/LICENSE +20 -0
  8. data/README.textile +80 -0
  9. data/Rakefile +59 -0
  10. data/VERSION +1 -0
  11. data/autotest/discover.rb +1 -0
  12. data/lib/active_schema.rb +30 -0
  13. data/lib/active_schema/active_record/base.rb +46 -0
  14. data/lib/active_schema/associations/by_foreign_key.rb +50 -0
  15. data/lib/active_schema/associations/generator.rb +25 -0
  16. data/lib/active_schema/configuration.rb +20 -0
  17. data/lib/active_schema/feeder.rb +45 -0
  18. data/lib/active_schema/in_advance_feeder.rb +10 -0
  19. data/lib/active_schema/on_the_fly_feeder.rb +26 -0
  20. data/lib/active_schema/schema_feeder.rb +41 -0
  21. data/lib/active_schema/table.rb +30 -0
  22. data/lib/active_schema/table_hub.rb +42 -0
  23. data/lib/active_schema/validations/by_column.rb +41 -0
  24. data/lib/active_schema/validations/by_index.rb +5 -0
  25. data/lib/active_schema/validations/generator.rb +45 -0
  26. data/nbproject/project.properties +7 -0
  27. data/nbproject/project.xml +15 -0
  28. data/spec/.rspec +1 -0
  29. data/spec/active_schema/active_record/base_spec.rb +118 -0
  30. data/spec/active_schema/associations/by_foreign_key_spec.rb +73 -0
  31. data/spec/active_schema/associations/generator_spec.rb +5 -0
  32. data/spec/active_schema/in_advance_feeder_spec.rb +25 -0
  33. data/spec/active_schema/on_the_fly_feeder_spec.rb +34 -0
  34. data/spec/active_schema/schema_feeder_spec.rb +111 -0
  35. data/spec/active_schema/table_hub_spec.rb +70 -0
  36. data/spec/active_schema/table_spec.rb +13 -0
  37. data/spec/active_schema/validations/by_column_spec.rb +47 -0
  38. data/spec/active_schema/validations/by_index_spec.rb +15 -0
  39. data/spec/active_schema/validations/generator_spec.rb +23 -0
  40. data/spec/active_schema_spec.rb +14 -0
  41. data/spec/spec_helper.rb +31 -0
  42. data/spec/support/establish_connection.rb +8 -0
  43. data/spec/support/model_macros.rb +31 -0
  44. data/spec/support/test_models.rb +12 -0
  45. metadata +366 -0
@@ -0,0 +1,8 @@
1
+ ActiveRecord::Base.establish_connection({
2
+ :adapter => 'mysql2',
3
+ :database => 'active_schema_test',
4
+ :user => 'mysql'
5
+
6
+ })
7
+
8
+ require 'foreigner'
@@ -0,0 +1,31 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module ModelMacros
5
+ def self.included(cls)
6
+ ['prisoners', 'facilities', 'wardens'].each do |table_name|
7
+ method_def = <<CODE
8
+ def #{table_name.singularize}_model
9
+ model_for("#{table_name}")
10
+ end
11
+
12
+ def #{table_name.singularize}_table
13
+ table_for("#{table_name}")
14
+ end
15
+ CODE
16
+ cls.class_eval(method_def)
17
+ end
18
+ end
19
+
20
+ def model_for(table_name)
21
+ new_model = Class.new(ActiveRecord::Base)
22
+ new_model.set_table_name table_name
23
+ new_model.stub!(:name).and_return(table_name.singularize.camelize)
24
+ new_model
25
+ end
26
+
27
+ def table_for(table_name)
28
+ ActiveSchema::Table.new(table_name, model_for(table_name))
29
+ end
30
+
31
+ end
@@ -0,0 +1,12 @@
1
+ module TableClassMethods
2
+ def table_with_indexes
3
+ tbl = ActiveSchema::Table.new(table_name, self)
4
+ connection.indexes(table_name).each {|index| tbl.add_index(index) }
5
+ tbl
6
+ end
7
+ end
8
+
9
+ class Prisoner < ActiveRecord::Base; end
10
+ class Warden < ActiveRecord::Base; end
11
+ class Facility < ActiveRecord::Base; end
12
+ [Prisoner, Warden, Facility].each {|cls| cls.extend(TableClassMethods) }
metadata ADDED
@@ -0,0 +1,366 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_schema
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Anders Johannsen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-03 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: foreigner
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 0
56
+ - 0
57
+ - beta
58
+ - 22
59
+ version: 2.0.0.beta.22
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: bundler
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 0
73
+ - 0
74
+ version: 1.0.0
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 1
87
+ - 5
88
+ - 0
89
+ - pre3
90
+ version: 1.5.0.pre3
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ name: rcov
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: rspec-rails
109
+ requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ segments:
115
+ - 2
116
+ - 0
117
+ - 0
118
+ - beta
119
+ - 22
120
+ version: 2.0.0.beta.22
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *id007
124
+ - !ruby/object:Gem::Dependency
125
+ name: autotest
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: *id008
137
+ - !ruby/object:Gem::Dependency
138
+ name: autotest-growl
139
+ requirement: &id009 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: *id009
150
+ - !ruby/object:Gem::Dependency
151
+ name: autotest-fsevent
152
+ requirement: &id010 !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: *id010
163
+ - !ruby/object:Gem::Dependency
164
+ name: spork
165
+ requirement: &id011 !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ type: :development
174
+ prerelease: false
175
+ version_requirements: *id011
176
+ - !ruby/object:Gem::Dependency
177
+ name: mysql2
178
+ requirement: &id012 !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ segments:
184
+ - 0
185
+ version: "0"
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: *id012
189
+ - !ruby/object:Gem::Dependency
190
+ name: foreigner
191
+ requirement: &id013 !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ segments:
197
+ - 0
198
+ version: "0"
199
+ type: :runtime
200
+ prerelease: false
201
+ version_requirements: *id013
202
+ - !ruby/object:Gem::Dependency
203
+ name: rspec
204
+ requirement: &id014 !ruby/object:Gem::Requirement
205
+ none: false
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ segments:
210
+ - 2
211
+ - 0
212
+ - 0
213
+ - beta
214
+ - 19
215
+ version: 2.0.0.beta.19
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: *id014
219
+ - !ruby/object:Gem::Dependency
220
+ name: bundler
221
+ requirement: &id015 !ruby/object:Gem::Requirement
222
+ none: false
223
+ requirements:
224
+ - - ~>
225
+ - !ruby/object:Gem::Version
226
+ segments:
227
+ - 1
228
+ - 0
229
+ - 0
230
+ version: 1.0.0
231
+ type: :development
232
+ prerelease: false
233
+ version_requirements: *id015
234
+ - !ruby/object:Gem::Dependency
235
+ name: jeweler
236
+ requirement: &id016 !ruby/object:Gem::Requirement
237
+ none: false
238
+ requirements:
239
+ - - ~>
240
+ - !ruby/object:Gem::Version
241
+ segments:
242
+ - 1
243
+ - 5
244
+ - 0
245
+ - pre3
246
+ version: 1.5.0.pre3
247
+ type: :development
248
+ prerelease: false
249
+ version_requirements: *id016
250
+ - !ruby/object:Gem::Dependency
251
+ name: rcov
252
+ requirement: &id017 !ruby/object:Gem::Requirement
253
+ none: false
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ segments:
258
+ - 0
259
+ version: "0"
260
+ type: :development
261
+ prerelease: false
262
+ version_requirements: *id017
263
+ description: "If you've gone through the trouble of linking your schema with proper foreign keys,\n defining associations in ActiveRecord feels like double work.\n\n ActiveSchema discovers the associations and validations that can be derived from the database schema.\n "
264
+ email: anders@johannsen.com
265
+ executables: []
266
+
267
+ extensions: []
268
+
269
+ extra_rdoc_files:
270
+ - LICENSE
271
+ - README.textile
272
+ files:
273
+ - .autotest
274
+ - .document
275
+ - .gitignore
276
+ - .rspec
277
+ - Gemfile
278
+ - Gemfile.lock
279
+ - LICENSE
280
+ - README.textile
281
+ - Rakefile
282
+ - VERSION
283
+ - autotest/discover.rb
284
+ - lib/active_schema.rb
285
+ - lib/active_schema/active_record/base.rb
286
+ - lib/active_schema/associations/by_foreign_key.rb
287
+ - lib/active_schema/associations/generator.rb
288
+ - lib/active_schema/configuration.rb
289
+ - lib/active_schema/feeder.rb
290
+ - lib/active_schema/in_advance_feeder.rb
291
+ - lib/active_schema/on_the_fly_feeder.rb
292
+ - lib/active_schema/schema_feeder.rb
293
+ - lib/active_schema/table.rb
294
+ - lib/active_schema/table_hub.rb
295
+ - lib/active_schema/validations/by_column.rb
296
+ - lib/active_schema/validations/by_index.rb
297
+ - lib/active_schema/validations/generator.rb
298
+ - nbproject/project.properties
299
+ - nbproject/project.xml
300
+ - spec/.rspec
301
+ - spec/active_schema/active_record/base_spec.rb
302
+ - spec/active_schema/associations/by_foreign_key_spec.rb
303
+ - spec/active_schema/associations/generator_spec.rb
304
+ - spec/active_schema/in_advance_feeder_spec.rb
305
+ - spec/active_schema/on_the_fly_feeder_spec.rb
306
+ - spec/active_schema/schema_feeder_spec.rb
307
+ - spec/active_schema/table_hub_spec.rb
308
+ - spec/active_schema/table_spec.rb
309
+ - spec/active_schema/validations/by_column_spec.rb
310
+ - spec/active_schema/validations/by_index_spec.rb
311
+ - spec/active_schema/validations/generator_spec.rb
312
+ - spec/active_schema_spec.rb
313
+ - spec/spec_helper.rb
314
+ - spec/support/establish_connection.rb
315
+ - spec/support/model_macros.rb
316
+ - spec/support/test_models.rb
317
+ has_rdoc: true
318
+ homepage: http://github.com/andersjo/active_schema
319
+ licenses: []
320
+
321
+ post_install_message:
322
+ rdoc_options: []
323
+
324
+ require_paths:
325
+ - lib
326
+ required_ruby_version: !ruby/object:Gem::Requirement
327
+ none: false
328
+ requirements:
329
+ - - ">="
330
+ - !ruby/object:Gem::Version
331
+ hash: 2540519664801620669
332
+ segments:
333
+ - 0
334
+ version: "0"
335
+ required_rubygems_version: !ruby/object:Gem::Requirement
336
+ none: false
337
+ requirements:
338
+ - - ">="
339
+ - !ruby/object:Gem::Version
340
+ segments:
341
+ - 0
342
+ version: "0"
343
+ requirements: []
344
+
345
+ rubyforge_project:
346
+ rubygems_version: 1.3.7
347
+ signing_key:
348
+ specification_version: 3
349
+ summary: Association discovery by foreign keys
350
+ test_files:
351
+ - spec/active_schema/active_record/base_spec.rb
352
+ - spec/active_schema/associations/by_foreign_key_spec.rb
353
+ - spec/active_schema/associations/generator_spec.rb
354
+ - spec/active_schema/in_advance_feeder_spec.rb
355
+ - spec/active_schema/on_the_fly_feeder_spec.rb
356
+ - spec/active_schema/schema_feeder_spec.rb
357
+ - spec/active_schema/table_hub_spec.rb
358
+ - spec/active_schema/table_spec.rb
359
+ - spec/active_schema/validations/by_column_spec.rb
360
+ - spec/active_schema/validations/by_index_spec.rb
361
+ - spec/active_schema/validations/generator_spec.rb
362
+ - spec/active_schema_spec.rb
363
+ - spec/spec_helper.rb
364
+ - spec/support/establish_connection.rb
365
+ - spec/support/model_macros.rb
366
+ - spec/support/test_models.rb