has_many_polymorphs 2.12 → 2.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +1 -0
  3. data/Manifest +1 -2
  4. data/README +7 -6
  5. data/Rakefile +28 -0
  6. data/generators/tagging/templates/tagging_extensions.rb +57 -7
  7. data/has_many_polymorphs.gemspec +25 -43
  8. data/lib/has_many_polymorphs.rb +1 -1
  9. data/lib/has_many_polymorphs/autoload.rb +3 -4
  10. data/lib/has_many_polymorphs/class_methods.rb +7 -3
  11. data/lib/has_many_polymorphs/configuration.rb +11 -9
  12. data/lib/has_many_polymorphs/reflection.rb +7 -6
  13. data/test/integration/app/config/environments/development.rb +2 -1
  14. data/test/integration/app/public/dispatch.cgi +0 -0
  15. data/test/integration/app/public/dispatch.fcgi +0 -0
  16. data/test/integration/app/public/dispatch.rb +0 -0
  17. data/test/integration/app/script/about +0 -0
  18. data/test/integration/app/script/breakpointer +0 -0
  19. data/test/integration/app/script/console +0 -0
  20. data/test/integration/app/script/destroy +0 -0
  21. data/test/integration/app/script/generate +0 -0
  22. data/test/integration/app/script/performance/benchmarker +0 -0
  23. data/test/integration/app/script/performance/profiler +0 -0
  24. data/test/integration/app/script/plugin +0 -0
  25. data/test/integration/app/script/process/inspector +0 -0
  26. data/test/integration/app/script/process/reaper +0 -0
  27. data/test/integration/app/script/process/spawner +0 -0
  28. data/test/integration/app/script/runner +0 -0
  29. data/test/integration/app/script/server +0 -0
  30. data/test/setup.rb +2 -2
  31. data/test/test_helper.rb +1 -1
  32. metadata +39 -10
  33. metadata.gz.sig +0 -0
  34. data/test/integration/app/db/schema.rb +0 -44
  35. data/test/integration/app/hmp_development +0 -0
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v2.13. Merge various fixes for Rails 2.2.2.
1
2
 
2
3
  v2.12. Improvements to the test suite; bugfixes for STI children (rsl). Remove fancy dependency system in favor of using Dispatcher::to_prepare every time.
3
4
 
data/Manifest CHANGED
@@ -22,6 +22,7 @@ lib/has_many_polymorphs/support_methods.rb
22
22
  lib/has_many_polymorphs.rb
23
23
  LICENSE
24
24
  Manifest
25
+ Rakefile
25
26
  README
26
27
  test/fixtures/bow_wows.yml
27
28
  test/fixtures/cats.yml
@@ -92,10 +93,8 @@ test/integration/app/db/migrate/006_create_double_sti_parents.rb
92
93
  test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb
93
94
  test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb
94
95
  test/integration/app/db/migrate/009_create_library_model.rb
95
- test/integration/app/db/schema.rb
96
96
  test/integration/app/doc/README_FOR_APP
97
97
  test/integration/app/generators/commenting_generator_test.rb
98
- test/integration/app/hmp_development
99
98
  test/integration/app/lib/library_model.rb
100
99
  test/integration/app/public/404.html
101
100
  test/integration/app/public/500.html
data/README CHANGED
@@ -1,13 +1,14 @@
1
-
2
1
  Has_many_polymorphs
3
2
 
4
3
  An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
5
4
 
6
5
  == License
7
6
 
8
- Copyright 2007 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file.
7
+ Copyright 2006-2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file.
8
+
9
+ The public certificate for the gem is here[http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem].
9
10
 
10
- The public certificate for this gem is at http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem.
11
+ If you use this software, please {make a donation}[http://blog.evanweaver.com/donate/], or {recommend Evan}[http://www.workingwithrails.com/person/7739-evan-weaver] at Working with Rails.
11
12
 
12
13
  == Description
13
14
 
@@ -28,14 +29,14 @@ The plugin also includes a generator for a tagging system, a common use case (se
28
29
 
29
30
  == Requirements
30
31
 
31
- * Rails 1.2.3 or greater
32
+ * Rails 2.2.2 or greater
32
33
 
33
34
  = Usage
34
35
 
35
36
  == Installation
36
37
 
37
38
  To install the Rails plugin, run:
38
- script/plugin install svn://rubyforge.org/var/svn/fauna/has_many_polymorphs/trunk
39
+ script/plugin install git://github.com/fauna/has_many_polymorphs.git
39
40
 
40
41
  There's also a gem version. To install it instead, run:
41
42
  sudo gem install has_many_polymorphs
@@ -187,7 +188,7 @@ Note that because of the way Rails reloads model classes, the plugin can sometim
187
188
 
188
189
  == Reporting problems
189
190
 
190
- * http://rubyforge.org/forum/forum.php?forum_id=16450
191
+ The support forum is here[http://rubyforge.org/forum/forum.php?forum_id=16450].
191
192
 
192
193
  Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.
193
194
 
@@ -0,0 +1,28 @@
1
+
2
+ require 'echoe'
3
+
4
+ Echoe.new("has_many_polymorphs") do |p|
5
+ p.project = "fauna"
6
+ p.summary = "An ActiveRecord plugin for self-referential and double-sided polymorphic associations."
7
+ p.url = "http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/"
8
+ p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
9
+ p.dependencies = ["activerecord"]
10
+ p.rdoc_pattern = /polymorphs\/association|polymorphs\/class_methods|polymorphs\/reflection|polymorphs\/autoload|polymorphs\/configuration|README|CHANGELOG|TODO|LICENSE|templates\/migration\.rb|templates\/tag\.rb|templates\/tagging\.rb|templates\/tagging_extensions\.rb/
11
+ p.require_signed = true
12
+ p.clean_pattern += ["**/ruby_sess*", "**/generated_models/**"]
13
+ p.test_pattern = ["test/unit/*_test.rb", "test/integration/*_test.rb", "test/generator/*_test.rb"]
14
+ end
15
+
16
+ desc "Run all the tests for every database adapter"
17
+ task "test_all" do
18
+ ['mysql', 'postgresql', 'sqlite3'].each do |adapter|
19
+ ENV['DB'] = adapter
20
+ ENV['PRODUCTION'] = nil
21
+ STDERR.puts "#{'='*80}\nDevelopment mode for #{adapter}\n#{'='*80}"
22
+ system("rake test:multi_rails:all")
23
+
24
+ ENV['PRODUCTION'] = '1'
25
+ STDERR.puts "#{'='*80}\nProduction mode for #{adapter}\n#{'='*80}"
26
+ system("rake test:multi_rails:all")
27
+ end
28
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  class ActiveRecord::Base #:nodoc:
3
2
 
4
3
  # These extensions make models taggable. This file is automatically generated and required by your app if you run the tagging generator included with has_many_polymorphs.
@@ -13,7 +12,7 @@ class ActiveRecord::Base #:nodoc:
13
12
  begin
14
13
  tag = Tag.find_or_create_by_name(tag_name)
15
14
  raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?
16
- tag.taggables << self
15
+ tags << tag
17
16
  rescue ActiveRecord::StatementInvalid => e
18
17
  raise unless e.to_s =~ /duplicate/i
19
18
  end
@@ -66,7 +65,11 @@ class ActiveRecord::Base #:nodoc:
66
65
  <%= parent_association_name -%>s.to_s
67
66
  #:startdoc:
68
67
  end
69
-
68
+
69
+ def tag_list=(value)
70
+ tag_with(value)
71
+ end
72
+
70
73
  private
71
74
 
72
75
  def tag_cast_to_string obj #:nodoc:
@@ -101,13 +104,14 @@ class ActiveRecord::Base #:nodoc:
101
104
  end
102
105
 
103
106
  module TaggingFinders
104
- #
105
107
  # Find all the objects tagged with the supplied list of tags
106
108
  #
107
109
  # Usage : Model.tagged_with("ruby")
108
110
  # Model.tagged_with("hello", "world")
109
111
  # Model.tagged_with("hello", "world", :limit => 10)
110
112
  #
113
+ # XXX This query strategy is not performant, and needs to be rewritten as an inverted join or a series of unions
114
+ #
111
115
  def tagged_with(*tag_list)
112
116
  options = tag_list.last.is_a?(Hash) ? tag_list.pop : {}
113
117
  tag_list = parse_tags(tag_list)
@@ -119,17 +123,22 @@ class ActiveRecord::Base #:nodoc:
119
123
  sql = "SELECT #{(scope && scope[:select]) || options[:select]} "
120
124
  sql << "FROM #{(scope && scope[:from]) || options[:from]} "
121
125
 
122
- add_joins!(sql, options, scope)
126
+ add_joins!(sql, options[:joins], scope)
123
127
 
124
128
  sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
125
129
  sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
126
130
  sql << "AND taggings.tag_id = tags.id "
127
131
 
128
- tag_list_condition = tag_list.map {|t| "'#{t}'"}.join(", ")
132
+ tag_list_condition = tag_list.map {|name| "'#{name}'"}.join(", ")
129
133
 
130
134
  sql << "AND (tags.name IN (#{sanitize_sql(tag_list_condition)})) "
131
135
  sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions]
132
- sql << "GROUP BY #{table_name}.id "
136
+
137
+ columns = column_names.map do |column|
138
+ "#{table_name}.#{column}"
139
+ end.join(", ")
140
+
141
+ sql << "GROUP BY #{columns} "
133
142
  sql << "HAVING COUNT(taggings.tag_id) = #{tag_list.size}"
134
143
 
135
144
  add_order!(sql, options[:order], scope)
@@ -138,6 +147,47 @@ class ActiveRecord::Base #:nodoc:
138
147
 
139
148
  find_by_sql(sql)
140
149
  end
150
+
151
+ def self.tagged_with_any(*tag_list)
152
+ options = tag_list.last.is_a?(Hash) ? tag_list.pop : {}
153
+ tag_list = parse_tags(tag_list)
154
+
155
+ scope = scope(:find)
156
+ options[:select] ||= "#{table_name}.*"
157
+ options[:from] ||= "#{table_name}, meta_tags, taggings"
158
+
159
+ sql = "SELECT #{(scope && scope[:select]) || options[:select]} "
160
+ sql << "FROM #{(scope && scope[:from]) || options[:from]} "
161
+
162
+ add_joins!(sql, options, scope)
163
+
164
+ sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
165
+ sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
166
+ sql << "AND taggings.meta_tag_id = meta_tags.id "
167
+
168
+ sql << "AND ("
169
+ or_options = []
170
+ tag_list.each do |name|
171
+ or_options << "meta_tags.name = '#{name}'"
172
+ end
173
+ or_options_joined = or_options.join(" OR ")
174
+ sql << "#{or_options_joined}) "
175
+
176
+
177
+ sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions]
178
+
179
+ columns = column_names.map do |column|
180
+ "#{table_name}.#{column}"
181
+ end.join(", ")
182
+
183
+ sql << "GROUP BY #{columns} "
184
+
185
+ add_order!(sql, options[:order], scope)
186
+ add_limit!(sql, options, scope)
187
+ add_lock!(sql, options, scope)
188
+
189
+ find_by_sql(sql)
190
+ end
141
191
 
142
192
  def parse_tags(tags)
143
193
  return [] if tags.blank?
@@ -1,58 +1,40 @@
1
-
2
- # Gem::Specification for Has_many_polymorphs-2.12
3
- # Originally generated by Echoe
1
+ # -*- encoding: utf-8 -*-
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = %q{has_many_polymorphs}
7
- s.version = "2.12"
8
-
9
- s.specification_version = 2 if s.respond_to? :specification_version=
5
+ s.version = "2.13"
10
6
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
12
8
  s.authors = [""]
13
- s.date = %q{2008-01-16}
9
+ s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"]
10
+ s.date = %q{2009-02-02}
14
11
  s.description = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.}
15
12
  s.email = %q{}
16
- s.files = ["CHANGELOG", "examples/hmph.rb", "generators/tagging/tagging_generator.rb", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tag_test.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "generators/tagging/templates/tagging_test.rb", "generators/tagging/templates/taggings.yml", "generators/tagging/templates/tags.yml", "init.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/base.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/debugging_tools.rb", "lib/has_many_polymorphs/rake_task_redefine_task.rb", "lib/has_many_polymorphs/reflection.rb", "lib/has_many_polymorphs/support_methods.rb", "lib/has_many_polymorphs.rb", "LICENSE", "Manifest", "README", "test/fixtures/bow_wows.yml", "test/fixtures/cats.yml", "test/fixtures/eaters_foodstuffs.yml", "test/fixtures/fish.yml", "test/fixtures/frogs.yml", "test/fixtures/keep_your_enemies_close.yml", "test/fixtures/little_whale_pupils.yml", "test/fixtures/people.yml", "test/fixtures/petfoods.yml", "test/fixtures/whales.yml", "test/fixtures/wild_boars.yml", "test/generator/tagging_generator_test.rb", "test/integration/app/app/controllers/application.rb", "test/integration/app/app/controllers/bones_controller.rb", "test/integration/app/app/helpers/addresses_helper.rb", "test/integration/app/app/helpers/application_helper.rb", "test/integration/app/app/helpers/bones_helper.rb", "test/integration/app/app/helpers/sellers_helper.rb", "test/integration/app/app/helpers/states_helper.rb", "test/integration/app/app/helpers/users_helper.rb", "test/integration/app/app/models/bone.rb", "test/integration/app/app/models/double_sti_parent.rb", "test/integration/app/app/models/double_sti_parent_relationship.rb", "test/integration/app/app/models/organic_substance.rb", "test/integration/app/app/models/single_sti_parent.rb", "test/integration/app/app/models/single_sti_parent_relationship.rb", "test/integration/app/app/models/stick.rb", "test/integration/app/app/models/stone.rb", "test/integration/app/app/views/addresses/edit.html.erb", "test/integration/app/app/views/addresses/index.html.erb", "test/integration/app/app/views/addresses/new.html.erb", "test/integration/app/app/views/addresses/show.html.erb", "test/integration/app/app/views/bones/index.rhtml", "test/integration/app/app/views/layouts/addresses.html.erb", "test/integration/app/app/views/layouts/sellers.html.erb", "test/integration/app/app/views/layouts/states.html.erb", "test/integration/app/app/views/layouts/users.html.erb", "test/integration/app/app/views/sellers/edit.html.erb", "test/integration/app/app/views/sellers/index.html.erb", "test/integration/app/app/views/sellers/new.html.erb", "test/integration/app/app/views/sellers/show.html.erb", "test/integration/app/app/views/states/edit.html.erb", "test/integration/app/app/views/states/index.html.erb", "test/integration/app/app/views/states/new.html.erb", "test/integration/app/app/views/states/show.html.erb", "test/integration/app/app/views/users/edit.html.erb", "test/integration/app/app/views/users/index.html.erb", "test/integration/app/app/views/users/new.html.erb", "test/integration/app/app/views/users/show.html.erb", "test/integration/app/config/boot.rb", "test/integration/app/config/database.yml", "test/integration/app/config/environment.rb", "test/integration/app/config/environment.rb.canonical", "test/integration/app/config/environments/development.rb", "test/integration/app/config/environments/production.rb", "test/integration/app/config/environments/test.rb", "test/integration/app/config/locomotive.yml", "test/integration/app/config/routes.rb", "test/integration/app/config/ultrasphinx/default.base", "test/integration/app/config/ultrasphinx/development.conf.canonical", "test/integration/app/db/migrate/001_create_sticks.rb", "test/integration/app/db/migrate/002_create_stones.rb", "test/integration/app/db/migrate/003_create_organic_substances.rb", "test/integration/app/db/migrate/004_create_bones.rb", "test/integration/app/db/migrate/005_create_single_sti_parents.rb", "test/integration/app/db/migrate/006_create_double_sti_parents.rb", "test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb", "test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb", "test/integration/app/db/migrate/009_create_library_model.rb", "test/integration/app/db/schema.rb", "test/integration/app/doc/README_FOR_APP", "test/integration/app/generators/commenting_generator_test.rb", "test/integration/app/hmp_development", "test/integration/app/lib/library_model.rb", "test/integration/app/public/404.html", "test/integration/app/public/500.html", "test/integration/app/public/dispatch.cgi", "test/integration/app/public/dispatch.fcgi", "test/integration/app/public/dispatch.rb", "test/integration/app/public/favicon.ico", "test/integration/app/public/images/rails.png", "test/integration/app/public/index.html", "test/integration/app/public/javascripts/application.js", "test/integration/app/public/javascripts/controls.js", "test/integration/app/public/javascripts/dragdrop.js", "test/integration/app/public/javascripts/effects.js", "test/integration/app/public/javascripts/prototype.js", "test/integration/app/public/robots.txt", "test/integration/app/public/stylesheets/scaffold.css", "test/integration/app/Rakefile", "test/integration/app/README", "test/integration/app/script/about", "test/integration/app/script/breakpointer", "test/integration/app/script/console", "test/integration/app/script/destroy", "test/integration/app/script/generate", "test/integration/app/script/performance/benchmarker", "test/integration/app/script/performance/profiler", "test/integration/app/script/plugin", "test/integration/app/script/process/inspector", "test/integration/app/script/process/reaper", "test/integration/app/script/process/spawner", "test/integration/app/script/runner", "test/integration/app/script/server", "test/integration/app/test/fixtures/double_sti_parent_relationships.yml", "test/integration/app/test/fixtures/double_sti_parents.yml", "test/integration/app/test/fixtures/organic_substances.yml", "test/integration/app/test/fixtures/single_sti_parent_relationships.yml", "test/integration/app/test/fixtures/single_sti_parents.yml", "test/integration/app/test/fixtures/sticks.yml", "test/integration/app/test/fixtures/stones.yml", "test/integration/app/test/functional/addresses_controller_test.rb", "test/integration/app/test/functional/bones_controller_test.rb", "test/integration/app/test/functional/sellers_controller_test.rb", "test/integration/app/test/functional/states_controller_test.rb", "test/integration/app/test/functional/users_controller_test.rb", "test/integration/app/test/test_helper.rb", "test/integration/app/test/unit/bone_test.rb", "test/integration/app/test/unit/double_sti_parent_relationship_test.rb", "test/integration/app/test/unit/double_sti_parent_test.rb", "test/integration/app/test/unit/organic_substance_test.rb", "test/integration/app/test/unit/single_sti_parent_relationship_test.rb", "test/integration/app/test/unit/single_sti_parent_test.rb", "test/integration/app/test/unit/stick_test.rb", "test/integration/app/test/unit/stone_test.rb", "test/integration/server_test.rb", "test/models/aquatic/fish.rb", "test/models/aquatic/pupils_whale.rb", "test/models/aquatic/whale.rb", "test/models/beautiful_fight_relationship.rb", "test/models/canine.rb", "test/models/cat.rb", "test/models/dog.rb", "test/models/eaters_foodstuff.rb", "test/models/frog.rb", "test/models/kitten.rb", "test/models/parentship.rb", "test/models/person.rb", "test/models/petfood.rb", "test/models/tabby.rb", "test/models/wild_boar.rb", "test/modules/extension_module.rb", "test/modules/other_extension_module.rb", "test/patches/symlinked_plugins_1.2.6.diff", "test/schema.rb", "test/setup.rb", "test/test_helper.rb", "test/unit/has_many_polymorphs_test.rb", "TODO", "has_many_polymorphs.gemspec"]
13
+ s.extra_rdoc_files = ["CHANGELOG", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/reflection.rb", "LICENSE", "README", "test/integration/app/doc/README_FOR_APP", "test/integration/app/README", "TODO"]
14
+ s.files = ["CHANGELOG", "examples/hmph.rb", "generators/tagging/tagging_generator.rb", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tag_test.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "generators/tagging/templates/tagging_test.rb", "generators/tagging/templates/taggings.yml", "generators/tagging/templates/tags.yml", "init.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/base.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/debugging_tools.rb", "lib/has_many_polymorphs/rake_task_redefine_task.rb", "lib/has_many_polymorphs/reflection.rb", "lib/has_many_polymorphs/support_methods.rb", "lib/has_many_polymorphs.rb", "LICENSE", "Manifest", "Rakefile", "README", "test/fixtures/bow_wows.yml", "test/fixtures/cats.yml", "test/fixtures/eaters_foodstuffs.yml", "test/fixtures/fish.yml", "test/fixtures/frogs.yml", "test/fixtures/keep_your_enemies_close.yml", "test/fixtures/little_whale_pupils.yml", "test/fixtures/people.yml", "test/fixtures/petfoods.yml", "test/fixtures/whales.yml", "test/fixtures/wild_boars.yml", "test/generator/tagging_generator_test.rb", "test/integration/app/app/controllers/application.rb", "test/integration/app/app/controllers/bones_controller.rb", "test/integration/app/app/helpers/addresses_helper.rb", "test/integration/app/app/helpers/application_helper.rb", "test/integration/app/app/helpers/bones_helper.rb", "test/integration/app/app/helpers/sellers_helper.rb", "test/integration/app/app/helpers/states_helper.rb", "test/integration/app/app/helpers/users_helper.rb", "test/integration/app/app/models/bone.rb", "test/integration/app/app/models/double_sti_parent.rb", "test/integration/app/app/models/double_sti_parent_relationship.rb", "test/integration/app/app/models/organic_substance.rb", "test/integration/app/app/models/single_sti_parent.rb", "test/integration/app/app/models/single_sti_parent_relationship.rb", "test/integration/app/app/models/stick.rb", "test/integration/app/app/models/stone.rb", "test/integration/app/app/views/addresses/edit.html.erb", "test/integration/app/app/views/addresses/index.html.erb", "test/integration/app/app/views/addresses/new.html.erb", "test/integration/app/app/views/addresses/show.html.erb", "test/integration/app/app/views/bones/index.rhtml", "test/integration/app/app/views/layouts/addresses.html.erb", "test/integration/app/app/views/layouts/sellers.html.erb", "test/integration/app/app/views/layouts/states.html.erb", "test/integration/app/app/views/layouts/users.html.erb", "test/integration/app/app/views/sellers/edit.html.erb", "test/integration/app/app/views/sellers/index.html.erb", "test/integration/app/app/views/sellers/new.html.erb", "test/integration/app/app/views/sellers/show.html.erb", "test/integration/app/app/views/states/edit.html.erb", "test/integration/app/app/views/states/index.html.erb", "test/integration/app/app/views/states/new.html.erb", "test/integration/app/app/views/states/show.html.erb", "test/integration/app/app/views/users/edit.html.erb", "test/integration/app/app/views/users/index.html.erb", "test/integration/app/app/views/users/new.html.erb", "test/integration/app/app/views/users/show.html.erb", "test/integration/app/config/boot.rb", "test/integration/app/config/database.yml", "test/integration/app/config/environment.rb", "test/integration/app/config/environment.rb.canonical", "test/integration/app/config/environments/development.rb", "test/integration/app/config/environments/production.rb", "test/integration/app/config/environments/test.rb", "test/integration/app/config/locomotive.yml", "test/integration/app/config/routes.rb", "test/integration/app/config/ultrasphinx/default.base", "test/integration/app/config/ultrasphinx/development.conf.canonical", "test/integration/app/db/migrate/001_create_sticks.rb", "test/integration/app/db/migrate/002_create_stones.rb", "test/integration/app/db/migrate/003_create_organic_substances.rb", "test/integration/app/db/migrate/004_create_bones.rb", "test/integration/app/db/migrate/005_create_single_sti_parents.rb", "test/integration/app/db/migrate/006_create_double_sti_parents.rb", "test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb", "test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb", "test/integration/app/db/migrate/009_create_library_model.rb", "test/integration/app/doc/README_FOR_APP", "test/integration/app/generators/commenting_generator_test.rb", "test/integration/app/lib/library_model.rb", "test/integration/app/public/404.html", "test/integration/app/public/500.html", "test/integration/app/public/dispatch.cgi", "test/integration/app/public/dispatch.fcgi", "test/integration/app/public/dispatch.rb", "test/integration/app/public/favicon.ico", "test/integration/app/public/images/rails.png", "test/integration/app/public/index.html", "test/integration/app/public/javascripts/application.js", "test/integration/app/public/javascripts/controls.js", "test/integration/app/public/javascripts/dragdrop.js", "test/integration/app/public/javascripts/effects.js", "test/integration/app/public/javascripts/prototype.js", "test/integration/app/public/robots.txt", "test/integration/app/public/stylesheets/scaffold.css", "test/integration/app/Rakefile", "test/integration/app/README", "test/integration/app/script/about", "test/integration/app/script/breakpointer", "test/integration/app/script/console", "test/integration/app/script/destroy", "test/integration/app/script/generate", "test/integration/app/script/performance/benchmarker", "test/integration/app/script/performance/profiler", "test/integration/app/script/plugin", "test/integration/app/script/process/inspector", "test/integration/app/script/process/reaper", "test/integration/app/script/process/spawner", "test/integration/app/script/runner", "test/integration/app/script/server", "test/integration/app/test/fixtures/double_sti_parent_relationships.yml", "test/integration/app/test/fixtures/double_sti_parents.yml", "test/integration/app/test/fixtures/organic_substances.yml", "test/integration/app/test/fixtures/single_sti_parent_relationships.yml", "test/integration/app/test/fixtures/single_sti_parents.yml", "test/integration/app/test/fixtures/sticks.yml", "test/integration/app/test/fixtures/stones.yml", "test/integration/app/test/functional/addresses_controller_test.rb", "test/integration/app/test/functional/bones_controller_test.rb", "test/integration/app/test/functional/sellers_controller_test.rb", "test/integration/app/test/functional/states_controller_test.rb", "test/integration/app/test/functional/users_controller_test.rb", "test/integration/app/test/test_helper.rb", "test/integration/app/test/unit/bone_test.rb", "test/integration/app/test/unit/double_sti_parent_relationship_test.rb", "test/integration/app/test/unit/double_sti_parent_test.rb", "test/integration/app/test/unit/organic_substance_test.rb", "test/integration/app/test/unit/single_sti_parent_relationship_test.rb", "test/integration/app/test/unit/single_sti_parent_test.rb", "test/integration/app/test/unit/stick_test.rb", "test/integration/app/test/unit/stone_test.rb", "test/integration/server_test.rb", "test/models/aquatic/fish.rb", "test/models/aquatic/pupils_whale.rb", "test/models/aquatic/whale.rb", "test/models/beautiful_fight_relationship.rb", "test/models/canine.rb", "test/models/cat.rb", "test/models/dog.rb", "test/models/eaters_foodstuff.rb", "test/models/frog.rb", "test/models/kitten.rb", "test/models/parentship.rb", "test/models/person.rb", "test/models/petfood.rb", "test/models/tabby.rb", "test/models/wild_boar.rb", "test/modules/extension_module.rb", "test/modules/other_extension_module.rb", "test/patches/symlinked_plugins_1.2.6.diff", "test/schema.rb", "test/setup.rb", "test/test_helper.rb", "test/unit/has_many_polymorphs_test.rb", "TODO", "has_many_polymorphs.gemspec"]
17
15
  s.has_rdoc = true
18
16
  s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Has_many_polymorphs", "--main", "README"]
19
18
  s.require_paths = ["lib"]
20
19
  s.rubyforge_project = %q{fauna}
21
- s.rubygems_version = %q{1.0.1}
20
+ s.rubygems_version = %q{1.3.1}
21
+ s.signing_key = %q{/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem}
22
22
  s.summary = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.}
23
23
  s.test_files = ["test/generator/tagging_generator_test.rb", "test/integration/server_test.rb", "test/unit/has_many_polymorphs_test.rb"]
24
24
 
25
- s.add_dependency(%q<activerecord>, [">= 0"])
26
- end
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
27
28
 
28
-
29
- # # Original Rakefile source (requires the Echoe gem):
30
- #
31
- #
32
- # require 'echoe'
33
- #
34
- # Echoe.new("has_many_polymorphs") do |p|
35
- # p.project = "fauna"
36
- # p.summary = "An ActiveRecord plugin for self-referential and double-sided polymorphic associations."
37
- # p.url = "http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/"
38
- # p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
39
- # p.dependencies = ["activerecord"]
40
- # p.rdoc_pattern = /polymorphs\/association|polymorphs\/class_methods|polymorphs\/reflection|polymorphs\/autoload|polymorphs\/configuration|README|CHANGELOG|TODO|LICENSE|templates\/migration\.rb|templates\/tag\.rb|templates\/tagging\.rb|templates\/tagging_extensions\.rb/
41
- # p.require_signed = true
42
- # p.clean_pattern += ["**/ruby_sess*", "**/generated_models/**"]
43
- # p.test_pattern = ["test/unit/*_test.rb", "test/integration/*_test.rb", "test/generator/*_test.rb"]
44
- # end
45
- #
46
- # desc "Run all the tests for every database adapter"
47
- # task "test_all" do
48
- # ['mysql', 'postgresql', 'sqlite3'].each do |adapter|
49
- # ENV['DB'] = adapter
50
- # ENV['PRODUCTION'] = nil
51
- # STDERR.puts "#{'='*80}\nDevelopment mode for #{adapter}\n#{'='*80}"
52
- # system("rake test:multi_rails:all")
53
- #
54
- # ENV['PRODUCTION'] = '1'
55
- # STDERR.puts "#{'='*80}\nProduction mode for #{adapter}\n#{'='*80}"
56
- # system("rake test:multi_rails:all")
57
- # end
58
- # end
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
31
+ s.add_development_dependency(%q<echoe>, [">= 0"])
32
+ else
33
+ s.add_dependency(%q<activerecord>, [">= 0"])
34
+ s.add_dependency(%q<echoe>, [">= 0"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<activerecord>, [">= 0"])
38
+ s.add_dependency(%q<echoe>, [">= 0"])
39
+ end
40
+ end
@@ -14,7 +14,7 @@ class ActiveRecord::Base
14
14
  extend ActiveRecord::Associations::PolymorphicClassMethods
15
15
  end
16
16
 
17
- if ENV['HMP_DEBUG'] or ENV['RAILS_ENV'] =~ /development|test/ and ENV['USER'] == 'eweaver'
17
+ if ENV['HMP_DEBUG'] || ENV['RAILS_ENV'] =~ /development|test/ && ENV['USER'] == 'eweaver'
18
18
  require 'has_many_polymorphs/debugging_tools'
19
19
  end
20
20
 
@@ -1,6 +1,5 @@
1
-
2
1
  require 'initializer' unless defined? ::Rails::Initializer
3
- require 'dispatcher' unless defined? ::ActionController::Dispatcher
2
+ require 'action_controller/dispatcher' unless defined? ::ActionController::Dispatcher
4
3
 
5
4
  module HasManyPolymorphs
6
5
 
@@ -37,7 +36,7 @@ Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_pol
37
36
  require requirement
38
37
  end
39
38
 
40
- Dir[options[:file_pattern]].each do |filename|
39
+ Dir.glob(options[:file_pattern]).each do |filename|
41
40
  next if filename =~ /#{options[:file_exclusions].join("|")}/
42
41
  open filename do |file|
43
42
  if file.grep(/#{options[:methods].join("|")}/).any?
@@ -64,7 +63,7 @@ class Rails::Initializer #:nodoc:
64
63
  alias_method_chain :after_initialize, :autoload
65
64
  end
66
65
 
67
- Dispatcher.to_prepare(:has_many_polymorphs_autoload) do
66
+ ActionController::Dispatcher.to_prepare(:has_many_polymorphs_autoload) do
68
67
  # Make sure it gets loaded in the app
69
68
  HasManyPolymorphs.autoload
70
69
  end
@@ -360,10 +360,14 @@ Be aware, however, that <tt>NULL != 'Spot'</tt> returns <tt>false</tt> due to SQ
360
360
  begin
361
361
  table = plural._as_class.table_name
362
362
  rescue NameError => e
363
- raise PolymorphicError, "Could not find a valid class for #{plural.inspect}. If it's namespaced, be sure to specify it as :\"module/#{plural}\" instead."
363
+ raise PolymorphicError, "Could not find a valid class for #{plural.inspect} (tried #{plural.to_s._classify}). If it's namespaced, be sure to specify it as :\"module/#{plural}\" instead."
364
364
  end
365
- plural._as_class.columns.map(&:name).each_with_index do |field, f_index|
366
- aliases["#{table}.#{field}"] = "t#{t_index}_r#{f_index}"
365
+ begin
366
+ plural._as_class.columns.map(&:name).each_with_index do |field, f_index|
367
+ aliases["#{table}.#{field}"] = "t#{t_index}_r#{f_index}"
368
+ end
369
+ rescue ActiveRecord::StatementInvalid => e
370
+ _logger_warn "Looks like your table doesn't exist for #{plural.to_s._classify}.\nError #{e}\nSkipping..."
367
371
  end
368
372
  end
369
373
  end
@@ -3,15 +3,17 @@
3
3
  Access the <tt>has_many_polymorphs_options</tt> hash in your Rails::Initializer.run#after_initialize block if you need to modify the behavior of Rails::Initializer::HasManyPolymorphsAutoload.
4
4
  =end
5
5
 
6
- class Rails::Configuration
6
+ module Rails #:nodoc:
7
+ class Configuration
7
8
 
8
- def has_many_polymorphs_options
9
- ::HasManyPolymorphs.options
10
- end
11
-
12
- def has_many_polymorphs_options=(hash)
13
- ::HasManyPolymorphs.options = HashWithIndifferentAccess.new(hash)
14
- end
15
-
9
+ def has_many_polymorphs_options
10
+ ::HasManyPolymorphs.options
11
+ end
12
+
13
+ def has_many_polymorphs_options=(hash)
14
+ ::HasManyPolymorphs.options = HashWithIndifferentAccess.new(hash)
15
+ end
16
+
17
+ end
16
18
  end
17
19
 
@@ -2,18 +2,19 @@ module ActiveRecord #:nodoc:
2
2
  module Reflection #:nodoc:
3
3
 
4
4
  module ClassMethods #:nodoc:
5
-
6
- # Update the default reflection switch so that <tt>:has_many_polymorphs</tt> types get instantiated. It's not a composed method so we have to override the whole thing.
5
+
6
+ # Update the default reflection switch so that <tt>:has_many_polymorphs</tt> types get instantiated.
7
+ # It's not a composed method so we have to override the whole thing.
7
8
  def create_reflection(macro, name, options, active_record)
8
9
  case macro
9
10
  when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
10
- reflection = AssociationReflection.new(macro, name, options, active_record)
11
+ klass = options[:through] ? ThroughReflection : AssociationReflection
12
+ reflection = klass.new(macro, name, options, active_record)
11
13
  when :composed_of
12
14
  reflection = AggregateReflection.new(macro, name, options, active_record)
13
- # added by has_many_polymorphs #
15
+ # added by has_many_polymorphs #
14
16
  when :has_many_polymorphs
15
17
  reflection = PolymorphicReflection.new(macro, name, options, active_record)
16
- # end added #
17
18
  end
18
19
  write_inheritable_hash :reflections, name => reflection
19
20
  reflection
@@ -32,7 +33,7 @@ Inherits from ActiveRecord::Reflection::AssociationReflection.
32
33
 
33
34
  =end
34
35
 
35
- class PolymorphicReflection < AssociationReflection
36
+ class PolymorphicReflection < ThroughReflection
36
37
  # Stub out the validity check. Has_many_polymorphs checks validity on macro creation, not on reflection.
37
38
  def check_validity!
38
39
  # nothing
@@ -3,6 +3,7 @@ config.cache_classes = ENV['PRODUCTION']
3
3
  config.whiny_nils = true
4
4
  config.action_controller.consider_all_requests_local = !ENV['PRODUCTION']
5
5
  config.action_controller.perform_caching = ENV['PRODUCTION']
6
- config.action_view.cache_template_extensions = ENV['PRODUCTION']
6
+ # The following has been deprecated in Rails 2.1 and removed in 2.2
7
+ config.action_view.cache_template_extensions = ENV['PRODUCTION'] if Rails::VERSION::MAJOR < 2 or Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR < 1
7
8
  config.action_view.debug_rjs = !ENV['PRODUCTION']
8
9
  config.action_mailer.raise_delivery_errors = false
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -6,8 +6,8 @@ Dir.chdir "#{File.dirname(__FILE__)}/integration/app/" do
6
6
  system("rm has_many_polymorphs; ln -s ../../../../../ has_many_polymorphs")
7
7
  end
8
8
 
9
- system "rake db:drop --trace RAILS_GEM_VERSION=2.0.2 "
10
- system "rake db:create --trace RAILS_GEM_VERSION=2.0.2 "
9
+ system "rake db:drop --trace RAILS_GEM_VERSION=2.2.2 "
10
+ system "rake db:create --trace RAILS_GEM_VERSION=2.2.2 "
11
11
  system "rake db:migrate --trace"
12
12
  system "rake db:fixtures:load --trace"
13
13
  end
@@ -23,7 +23,7 @@ LOG = "#{HERE}/integration/app/log/development.log"
23
23
  require 'integration/app/config/environment'
24
24
  require 'test_help'
25
25
 
26
- Inflector.inflections {|i| i.irregular 'fish', 'fish' }
26
+ ActiveSupport::Inflector.inflections {|i| i.irregular 'fish', 'fish' }
27
27
 
28
28
  $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path = HERE + "/fixtures")
29
29
  $LOAD_PATH.unshift(HERE + "/models")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_many_polymorphs
3
3
  version: !ruby/object:Gem::Version
4
- version: "2.12"
4
+ version: "2.13"
5
5
  platform: ruby
6
6
  authors:
7
7
  - ""
@@ -30,11 +30,22 @@ cert_chain:
30
30
  yZ0=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-01-16 00:00:00 -05:00
33
+ date: 2009-02-02 00:00:00 -08:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: echoe
48
+ type: :development
38
49
  version_requirement:
39
50
  version_requirements: !ruby/object:Gem::Requirement
40
51
  requirements:
@@ -48,8 +59,22 @@ executables: []
48
59
 
49
60
  extensions: []
50
61
 
51
- extra_rdoc_files: []
52
-
62
+ extra_rdoc_files:
63
+ - CHANGELOG
64
+ - generators/tagging/templates/migration.rb
65
+ - generators/tagging/templates/tag.rb
66
+ - generators/tagging/templates/tagging.rb
67
+ - generators/tagging/templates/tagging_extensions.rb
68
+ - lib/has_many_polymorphs/association.rb
69
+ - lib/has_many_polymorphs/autoload.rb
70
+ - lib/has_many_polymorphs/class_methods.rb
71
+ - lib/has_many_polymorphs/configuration.rb
72
+ - lib/has_many_polymorphs/reflection.rb
73
+ - LICENSE
74
+ - README
75
+ - test/integration/app/doc/README_FOR_APP
76
+ - test/integration/app/README
77
+ - TODO
53
78
  files:
54
79
  - CHANGELOG
55
80
  - examples/hmph.rb
@@ -75,6 +100,7 @@ files:
75
100
  - lib/has_many_polymorphs.rb
76
101
  - LICENSE
77
102
  - Manifest
103
+ - Rakefile
78
104
  - README
79
105
  - test/fixtures/bow_wows.yml
80
106
  - test/fixtures/cats.yml
@@ -145,10 +171,8 @@ files:
145
171
  - test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb
146
172
  - test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb
147
173
  - test/integration/app/db/migrate/009_create_library_model.rb
148
- - test/integration/app/db/schema.rb
149
174
  - test/integration/app/doc/README_FOR_APP
150
175
  - test/integration/app/generators/commenting_generator_test.rb
151
- - test/integration/app/hmp_development
152
176
  - test/integration/app/lib/library_model.rb
153
177
  - test/integration/app/public/404.html
154
178
  - test/integration/app/public/500.html
@@ -229,8 +253,13 @@ files:
229
253
  has_rdoc: true
230
254
  homepage: http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/
231
255
  post_install_message:
232
- rdoc_options: []
233
-
256
+ rdoc_options:
257
+ - --line-numbers
258
+ - --inline-source
259
+ - --title
260
+ - Has_many_polymorphs
261
+ - --main
262
+ - README
234
263
  require_paths:
235
264
  - lib
236
265
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -243,12 +272,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
272
  requirements:
244
273
  - - ">="
245
274
  - !ruby/object:Gem::Version
246
- version: "0"
275
+ version: "1.2"
247
276
  version:
248
277
  requirements: []
249
278
 
250
279
  rubyforge_project: fauna
251
- rubygems_version: 1.0.1
280
+ rubygems_version: 1.3.1
252
281
  signing_key:
253
282
  specification_version: 2
254
283
  summary: An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
metadata.gz.sig CHANGED
Binary file
@@ -1,44 +0,0 @@
1
- # This file is autogenerated. Instead of editing this file, please use the
2
- # migrations feature of ActiveRecord to incrementally modify your database, and
3
- # then regenerate this schema definition.
4
-
5
- ActiveRecord::Schema.define(:version => 9) do
6
-
7
- create_table "double_sti_parent_relationships", :force => true do |t|
8
- t.column "the_bone_type", :string, :default => "", :null => false
9
- t.column "the_bone_id", :integer, :null => false
10
- t.column "parent_type", :string, :default => "", :null => false
11
- t.column "parent_id", :integer, :null => false
12
- end
13
-
14
- create_table "double_sti_parents", :force => true do |t|
15
- t.column "name", :string
16
- end
17
-
18
- create_table "library_models", :force => true do |t|
19
- t.column "name", :string
20
- end
21
-
22
- create_table "organic_substances", :force => true do |t|
23
- t.column "type", :string
24
- end
25
-
26
- create_table "single_sti_parent_relationships", :force => true do |t|
27
- t.column "the_bone_type", :string, :default => "", :null => false
28
- t.column "the_bone_id", :integer, :null => false
29
- t.column "single_sti_parent_id", :integer, :null => false
30
- end
31
-
32
- create_table "single_sti_parents", :force => true do |t|
33
- t.column "name", :string
34
- end
35
-
36
- create_table "sticks", :force => true do |t|
37
- t.column "name", :string
38
- end
39
-
40
- create_table "stones", :force => true do |t|
41
- t.column "name", :string
42
- end
43
-
44
- end