molo 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/Molo.gemspec +56 -2
  2. data/README.markdown +31 -7
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/tasks/molo.rb +9 -3
  6. data/vendor/rails_sql_views/.gitignore +3 -0
  7. data/vendor/rails_sql_views/CHANGELOG +22 -0
  8. data/vendor/rails_sql_views/CONTRIB +8 -0
  9. data/vendor/rails_sql_views/LICENSE +7 -0
  10. data/vendor/rails_sql_views/README +51 -0
  11. data/vendor/rails_sql_views/Rakefile +74 -0
  12. data/vendor/rails_sql_views/TODO +2 -0
  13. data/vendor/rails_sql_views/VERSION +1 -0
  14. data/vendor/rails_sql_views/init.rb +1 -0
  15. data/vendor/rails_sql_views/lib/active_record/view.rb +76 -0
  16. data/vendor/rails_sql_views/lib/core_ext/module.rb +13 -0
  17. data/vendor/rails_sql_views/lib/rails_sql_views.rb +47 -0
  18. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract/schema_definitions.rb +63 -0
  19. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb +79 -0
  20. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract_adapter.rb +41 -0
  21. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/mysql2_adapter.rb +62 -0
  22. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/mysql_adapter.rb +62 -0
  23. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oci_adapter.rb +33 -0
  24. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracle_adapter.rb +33 -0
  25. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb +39 -0
  26. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb.orig +72 -0
  27. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb +65 -0
  28. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig +69 -0
  29. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlite_adapter.rb +66 -0
  30. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb +43 -0
  31. data/vendor/rails_sql_views/lib/rails_sql_views/loader.rb +18 -0
  32. data/vendor/rails_sql_views/lib/rails_sql_views/schema_dumper.rb +112 -0
  33. data/vendor/rails_sql_views/lib/rails_sql_views/version.rb +9 -0
  34. data/vendor/rails_sql_views/rails/init.rb +1 -0
  35. data/vendor/rails_sql_views/rails_sql_views.gemspec +81 -0
  36. data/vendor/rails_sql_views/test/.gitignore +1 -0
  37. data/vendor/rails_sql_views/test/README +63 -0
  38. data/vendor/rails_sql_views/test/adapter_test.rb +82 -0
  39. data/vendor/rails_sql_views/test/connection.example.yml +12 -0
  40. data/vendor/rails_sql_views/test/connection/native_mysql/connection.rb +32 -0
  41. data/vendor/rails_sql_views/test/connection/native_mysql/schema.sql +33 -0
  42. data/vendor/rails_sql_views/test/connection/native_postgresql/connection.rb +31 -0
  43. data/vendor/rails_sql_views/test/connection/native_postgresql/schema.sql +33 -0
  44. data/vendor/rails_sql_views/test/connection/oracle_enhanced/connection.rb +29 -0
  45. data/vendor/rails_sql_views/test/connection/oracle_enhanced/procedures.sql +15 -0
  46. data/vendor/rails_sql_views/test/connection/oracle_enhanced/schema.sql +39 -0
  47. data/vendor/rails_sql_views/test/models/item.rb +4 -0
  48. data/vendor/rails_sql_views/test/models/person.rb +5 -0
  49. data/vendor/rails_sql_views/test/models/person2.rb +3 -0
  50. data/vendor/rails_sql_views/test/models/place.rb +2 -0
  51. data/vendor/rails_sql_views/test/models/v_person.rb +4 -0
  52. data/vendor/rails_sql_views/test/models/v_profile.rb +3 -0
  53. data/vendor/rails_sql_views/test/schema.native_mysql.expected.rb +51 -0
  54. data/vendor/rails_sql_views/test/schema.native_postgresql.expected.rb +51 -0
  55. data/vendor/rails_sql_views/test/schema.oracle_enhanced.expected.rb +51 -0
  56. data/vendor/rails_sql_views/test/schema_dumper_test.rb +117 -0
  57. data/vendor/rails_sql_views/test/test_helper.rb +30 -0
  58. data/vendor/rails_sql_views/test/view_model_test.rb +63 -0
  59. data/vendor/rails_sql_views/test/view_operations_test.rb +36 -0
  60. data/vendor/yaml_db/lib/serialization_helper.rb +15 -10
  61. metadata +58 -4
data/Molo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{molo}
8
- s.version = "0.6.0"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joel Moss", "Todd Huss", "Michael Grosser"]
12
- s.date = %q{2010-12-14}
12
+ s.date = %q{2010-12-16}
13
13
  s.email = %q{joel@developwithstyle.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -28,6 +28,60 @@ Gem::Specification.new do |s|
28
28
  "vendor/migration_helpers/README.markdown",
29
29
  "vendor/migration_helpers/init.rb",
30
30
  "vendor/migration_helpers/lib/migration_helper.rb",
31
+ "vendor/rails_sql_views/.gitignore",
32
+ "vendor/rails_sql_views/CHANGELOG",
33
+ "vendor/rails_sql_views/CONTRIB",
34
+ "vendor/rails_sql_views/LICENSE",
35
+ "vendor/rails_sql_views/README",
36
+ "vendor/rails_sql_views/Rakefile",
37
+ "vendor/rails_sql_views/TODO",
38
+ "vendor/rails_sql_views/VERSION",
39
+ "vendor/rails_sql_views/init.rb",
40
+ "vendor/rails_sql_views/lib/active_record/view.rb",
41
+ "vendor/rails_sql_views/lib/core_ext/module.rb",
42
+ "vendor/rails_sql_views/lib/rails_sql_views.rb",
43
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract/schema_definitions.rb",
44
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb",
45
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract_adapter.rb",
46
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/mysql2_adapter.rb",
47
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/mysql_adapter.rb",
48
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oci_adapter.rb",
49
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracle_adapter.rb",
50
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb",
51
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb.orig",
52
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb",
53
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig",
54
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlite_adapter.rb",
55
+ "vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb",
56
+ "vendor/rails_sql_views/lib/rails_sql_views/loader.rb",
57
+ "vendor/rails_sql_views/lib/rails_sql_views/schema_dumper.rb",
58
+ "vendor/rails_sql_views/lib/rails_sql_views/version.rb",
59
+ "vendor/rails_sql_views/rails/init.rb",
60
+ "vendor/rails_sql_views/rails_sql_views.gemspec",
61
+ "vendor/rails_sql_views/test/.gitignore",
62
+ "vendor/rails_sql_views/test/README",
63
+ "vendor/rails_sql_views/test/adapter_test.rb",
64
+ "vendor/rails_sql_views/test/connection.example.yml",
65
+ "vendor/rails_sql_views/test/connection/native_mysql/connection.rb",
66
+ "vendor/rails_sql_views/test/connection/native_mysql/schema.sql",
67
+ "vendor/rails_sql_views/test/connection/native_postgresql/connection.rb",
68
+ "vendor/rails_sql_views/test/connection/native_postgresql/schema.sql",
69
+ "vendor/rails_sql_views/test/connection/oracle_enhanced/connection.rb",
70
+ "vendor/rails_sql_views/test/connection/oracle_enhanced/procedures.sql",
71
+ "vendor/rails_sql_views/test/connection/oracle_enhanced/schema.sql",
72
+ "vendor/rails_sql_views/test/models/item.rb",
73
+ "vendor/rails_sql_views/test/models/person.rb",
74
+ "vendor/rails_sql_views/test/models/person2.rb",
75
+ "vendor/rails_sql_views/test/models/place.rb",
76
+ "vendor/rails_sql_views/test/models/v_person.rb",
77
+ "vendor/rails_sql_views/test/models/v_profile.rb",
78
+ "vendor/rails_sql_views/test/schema.native_mysql.expected.rb",
79
+ "vendor/rails_sql_views/test/schema.native_postgresql.expected.rb",
80
+ "vendor/rails_sql_views/test/schema.oracle_enhanced.expected.rb",
81
+ "vendor/rails_sql_views/test/schema_dumper_test.rb",
82
+ "vendor/rails_sql_views/test/test_helper.rb",
83
+ "vendor/rails_sql_views/test/view_model_test.rb",
84
+ "vendor/rails_sql_views/test/view_operations_test.rb",
31
85
  "vendor/yaml_db/init.rb",
32
86
  "vendor/yaml_db/lib/csv_db.rb",
33
87
  "vendor/yaml_db/lib/serialization_helper.rb",
data/README.markdown CHANGED
@@ -1,9 +1,33 @@
1
- Molo
1
+ Molo (We're riding solo!)
2
2
  ====
3
3
 
4
- Rails migrations in non-Rails (and non Ruby) projects.
5
-
6
- Install Ruby, RubyGems and a ruby-database driver (e.g. `gem install mysql`) then:
4
+ Molo provides Rails database migrations for non-Rails and non-Ruby projects. By dropping a Rakefile into your projects root, Molo will provide you with a list of Rake tasks for managing your database schema and data.
5
+
6
+ The following tasks are provided:
7
+
8
+ rake db:data:dump # Dump contents of database to db/data.extension (defaults to yaml)
9
+ rake db:data:dump_dir # Dump contents of database to db/data/tablename.extension (defaults to yaml)
10
+ rake db:data:load # Load contents of db/data.extension (defaults to yaml) into database
11
+ rake db:data:load_dir # Load contents of db/data/* into database
12
+ rake db:dump # Dump schema and data to db/schema.rb and db/data.yml
13
+ rake db:load # Load schema and data from db/schema.rb and db/data.yml
14
+ rake db:migrate # Migrate the database using the scripts in the migrations directory.
15
+ rake db:migrate:down # Runs the "down" for a given migration VERSION.
16
+ rake db:migrate:redo # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).
17
+ rake db:migrate:status # Display status of migrations
18
+ rake db:migrate:up # Runs the "up" for a given migration VERSION.
19
+ rake db:new_migration # Create a new migration
20
+ rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
21
+ rake db:schema:dump # Create schema.rb file that can be portably used against any DB supported by AR
22
+ rake db:schema:load # Load a ar_schema.rb file into the database
23
+ rake db:test:load # Recreate the test database from the current schema.rb
24
+ rake db:test:prepare # Check for pending migrations and load the test schema
25
+ rake db:test:purge # Empty the test database
26
+ rake db:version # Retrieves the current schema version number
27
+
28
+ ### Installation
29
+
30
+ Install Ruby, RubyGems and a ruby-database driver (e.g. `gem install mysql2`) then:
7
31
 
8
32
  sudo gem install molo
9
33
 
@@ -21,10 +45,10 @@ Add to `Rakefile` in your projects base directory:
21
45
  # t.log_level = Logger::ERROR
22
46
  end
23
47
  rescue LoadError => e
24
- puts "gem install molo to get db:migrate:* tasks! (Error: #{e})"
48
+ puts "Run 'gem install molo' to get db:migrate:* tasks! (Error: #{e})"
25
49
  end
26
50
 
27
- Add database configuration to `db/config.yml` in your projects base directory e.g.:
51
+ Create a `db` directory at your project root and add database configuration to `db/config.yml`. Here's an example DB config.
28
52
 
29
53
  development:
30
54
  adapter: sqlite3
@@ -42,7 +66,7 @@ Add database configuration to `db/config.yml` in your projects base directory e.
42
66
  password:
43
67
  socket: /var/run/mysqld/mysqld.sock
44
68
 
45
- test: &test
69
+ test:
46
70
  adapter: sqlite3
47
71
  database: db/test.sqlite3
48
72
  pool: 5
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  gem.summary = "A thin wrapper to use Rails Migrations in non Rails projects"
10
10
  gem.email = "joel@developwithstyle.com"
11
11
  gem.homepage = "http://codaset.com/joelmoss/molo"
12
- gem.authors = ["Joel Moss","Todd Huss", "Michael Grosser"]
12
+ gem.authors = ["Joel Moss", "Todd Huss", "Michael Grosser"]
13
13
  gem.files += ["lib/tasks/*"]
14
14
  gem.add_dependency "activerecord", "~> 3.0.3"
15
15
  gem.add_dependency "rake", "~> 0.8"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
data/lib/tasks/molo.rb CHANGED
@@ -35,6 +35,7 @@ class MigratorTasks < ::Rake::TaskLib
35
35
  require 'active_record'
36
36
  require 'erb'
37
37
  require 'yaml_db'
38
+ require 'rails_sql_views'
38
39
 
39
40
  ENV[@env] ||= @default_env
40
41
 
@@ -212,7 +213,12 @@ class MigratorTasks < ::Rake::TaskLib
212
213
  task(:load => [ "db:schema:load", "db:data:load" ])
213
214
 
214
215
  namespace :data do
215
- def db_dump_data_file (extension = "yml")
216
+ table_options = {
217
+ :only => ENV['only'] || [],
218
+ :except => ENV['except'] || []
219
+ }
220
+
221
+ def db_dump_data_file(extension = "yml")
216
222
  "#{dump_dir}/data.#{extension}"
217
223
  end
218
224
 
@@ -224,14 +230,14 @@ class MigratorTasks < ::Rake::TaskLib
224
230
  task :dump => :ar_init do
225
231
  format_class = ENV['class'] || "YamlDb::Helper"
226
232
  helper = format_class.constantize
227
- SerializationHelper::Base.new(helper).dump db_dump_data_file helper.extension
233
+ SerializationHelper::Base.new(helper).dump db_dump_data_file(helper.extension), table_options
228
234
  end
229
235
 
230
236
  desc "Dump contents of database to db/data/tablename.extension (defaults to yaml)"
231
237
  task :dump_dir => :ar_init do
232
238
  format_class = ENV['class'] || "YamlDb::Helper"
233
239
  dir = ENV['dir'] || "data"
234
- SerializationHelper::Base.new(format_class.constantize).dump_to_dir dump_dir("/#{dir}")
240
+ SerializationHelper::Base.new(format_class.constantize).dump_to_dir dump_dir("/#{dir}"), table_options
235
241
  end
236
242
 
237
243
  desc "Load contents of db/data.extension (defaults to yaml) into database"
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *~
3
+ test/connection.yml
@@ -0,0 +1,22 @@
1
+ 0.1.0 - Released Dec 27, 2006
2
+ * Initial release
3
+
4
+ 0.5.0 - Released Dec 29, 2006
5
+ * Added support for PostgreSQL (Michael Schuerig)
6
+ * Fixed the schema dumper
7
+
8
+ 0.5.1 - Released Jan 10, 2007
9
+ * Patch by Clifford T. Matthews to use String.dump to dump out the view select statement
10
+
11
+ 0.6.0 - Released May 9, 2007
12
+ * Added support for SQL Server (Seth Ladd)-
13
+ * Added support for using views to map non-friendly database field names to AR-friendly names (Nathan Vack)
14
+ * Added support for Oracle (Alistair Davidson)
15
+
16
+ 0.6.1 - Released June 6, 2007
17
+ * Added test for union support
18
+ * Updated tests to include new table to support union test
19
+
20
+ 0.7.0
21
+ * Updated dependency versions to get on ActiveRecord 2.x. May not be compatible with Rails versions less than 2.x.
22
+ * Add nonview_tables support to *all* of the adapters (was missing from Postgres and SQLServer)
@@ -0,0 +1,8 @@
1
+ The following people have kindly contributed to improve Rails SQL Views:
2
+
3
+ Anthony Eden
4
+ Michael Schuerig
5
+ Clifford T. Matthews
6
+ Seth Ladd
7
+
8
+ So if you see them in the halls of your local Ruby or Rails gatherings please remember to say Hi and Thanks. ;-)
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2006-2008 Anthony Eden
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ == Rails SQL Views
2
+
3
+ Library which adds SQL Views to Rails. Adds create_view and drop_view to the ActiveRecord::ConnectionAdapters::AbstractAdapter (which makes them available to migrations) and adds support for dumping views in the ActiveRecord::SchemaDumper.
4
+
5
+ == Installation
6
+
7
+ To install:
8
+
9
+ gem install rails_sql_views
10
+
11
+ Then add the following to your Rails config/environment.rb:
12
+
13
+ require_gem 'rails_sql_views'
14
+ require 'rails_sql_views'
15
+
16
+ == Usage
17
+
18
+ You can then use create_view and drop_view in your migrations. For example:
19
+
20
+ class CreatePersonView < ActiveRecord::Migration
21
+ def self.up
22
+ create_view :v_people, "select * from people" do |t|
23
+ t.column :id
24
+ t.column :name
25
+ t.column :social_security
26
+ end
27
+ end
28
+
29
+ def self.down
30
+ drop_view :v_people
31
+ end
32
+ end
33
+
34
+ This extension also adds support for views in the ActiveRecord::SchemaDumper class.
35
+
36
+ The following drivers are supported:
37
+
38
+ MySQL
39
+ PostgreSQL (Native and Pure Ruby)
40
+ Oracle
41
+ SQL Server
42
+
43
+ == Known Issues
44
+
45
+ * Drivers not mentioned above are not supported.
46
+
47
+ If you find any issues please send an email to anthonyeden@gmail.com .
48
+
49
+ == Contributing
50
+
51
+ If you would like to implement view support for other adapters then please drop me an email. Better yet, write up the adapter modifications and send them to me. :-)
@@ -0,0 +1,74 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+
7
+ require File.join(File.dirname(__FILE__), 'lib/rails_sql_views', 'version')
8
+
9
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
+ PKG_NAME = 'rails_sql_views'
11
+ PKG_VERSION = RailsSqlViews::VERSION::STRING + PKG_BUILD
12
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
+ PKG_DESTINATION = ENV["PKG_DESTINATION"] || "../#{PKG_NAME}"
14
+
15
+ RELEASE_NAME = "REL #{PKG_VERSION}"
16
+
17
+ RUBY_FORGE_PROJECT = "activewarehouse"
18
+ RUBY_FORGE_USER = "aeden"
19
+
20
+ desc 'Default: run unit tests.'
21
+ task :default => :test
22
+
23
+ desc 'Test the library.'
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = true
28
+ end
29
+
30
+ namespace :rcov do
31
+ desc 'Measures test coverage'
32
+ task :test do
33
+ rm_f 'coverage.data'
34
+ mkdir 'coverage' unless File.exist?('coverage')
35
+ rcov = "rcov --aggregate coverage.data --text-summary -Ilib"
36
+ system("#{rcov} test/*_test.rb test/**/*_test.rb")
37
+ system("open coverage/index.html") if PLATFORM['darwin']
38
+ end
39
+ end
40
+
41
+ desc 'Generate documentation library.'
42
+ Rake::RDocTask.new(:rdoc) do |rdoc|
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = 'Rails SQL Views'
45
+ rdoc.options << '--line-numbers' << '--inline-source'
46
+ rdoc.rdoc_files.include('README')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
49
+
50
+ begin
51
+ require 'jeweler'
52
+ Jeweler::Tasks.new do |s|
53
+ s.name = "rails_sql_views"
54
+ s.summary = "Library which adds SQL Views to ActiveRecord."
55
+ s.email = "josh@technicalpickles.com"
56
+ s.homepage = "http://activewarehouse.rubyforge.org/rails_sql_views"
57
+ s.description = "Adds support for using SQL views within ActiveRecord"
58
+ s.authors = ["Anthony Eden"]
59
+ s.files = FileList[
60
+ "CHANGELOG",
61
+ "README",
62
+ "Rakefile",
63
+ "{bin,lib}/**/*"
64
+ ]
65
+ s.add_dependency 'activerecord'
66
+ end
67
+ rescue LoadError
68
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
69
+ end
70
+
71
+ desc "Publish the API documentation"
72
+ task :pdoc => [:rdoc] do
73
+ Rake::SshDirPublisher.new("aeden@rubyforge.org", "/var/www/gforge-projects/activewarehouse/rails_sql_views/rdoc", "rdoc").upload
74
+ end
@@ -0,0 +1,2 @@
1
+
2
+ - Use pre-existing Adapter#supports_views? where possible
@@ -0,0 +1 @@
1
+ 0.8.0
@@ -0,0 +1 @@
1
+ require 'rails_sql_views'
@@ -0,0 +1,76 @@
1
+
2
+ # A base class for database views.
3
+ # It is primarily useful for views that are centered around a single table/model.
4
+ module ActiveRecord # :nodoc:
5
+ class View < Base
6
+ self.abstract_class = true
7
+
8
+ def readonly?
9
+ true
10
+ end
11
+
12
+ class << self
13
+ # Clones all applicable associations from +model+ to this view
14
+ # and provides an instance method
15
+ # <tt>to_<em>model</em></tt>
16
+ # that casts a view object to an object of the kind view is
17
+ # based on. This latter object may be missing attributes; to fill
18
+ # them in, call #reload.
19
+ def based_on(model)
20
+ define_method("to_#{model.name.demodulize.underscore}") do
21
+ becomes(model)
22
+ end
23
+
24
+ model.reflect_on_all_associations.each do |assoc|
25
+ clone_association(model, assoc)
26
+ end
27
+ end
28
+
29
+ # Clone one or more associations from +model+ to this view class.
30
+ #
31
+ # NOTE: Currently only <tt>belongs_to</tt>, <tt>has_many</tt> (withouth
32
+ # <tt>:through</tt>), and <tt>has_and_belongs_to_many</tt> associations
33
+ # are supported.
34
+ def clone_association(model, *associations)
35
+ associations.each do |association|
36
+ r = case association
37
+ when String, Symbol
38
+ model.reflect_on_association(association.to_sym)
39
+ when ActiveRecord::Reflection::AssociationReflection
40
+ association
41
+ else
42
+ raise ArgumentError, "Unrecognized association #{association.inspect}; must be a Symbol, String, or AssociationReflection."
43
+ end
44
+ case r.macro
45
+ when :belongs_to
46
+ if self.column_names.include?(r.primary_key_name.to_s)
47
+ if !r.options[:foreign_type] || self.column_names.include?(r.options[:foreign_type])
48
+ options = r.options.merge(
49
+ :class_name => r.class_name,
50
+ :foreign_key => r.primary_key_name
51
+ )
52
+ belongs_to r.name, options
53
+ end
54
+ end
55
+ when :has_many
56
+ ### TODO :through assocications
57
+ options = r.options.merge(
58
+ :class_name => r.class_name,
59
+ :foreign_key => r.primary_key_name
60
+ )
61
+ has_many r.name, options
62
+ when :has_and_belongs_to_many
63
+ options = r.options.merge(
64
+ :class_name => r.class_name,
65
+ :foreign_key => r.primary_key_name,
66
+ :association_foreign_key => r.association_foreign_key
67
+ )
68
+ has_and_belongs_to_many r.name, options
69
+ when :has_one
70
+ ### TODO
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end