johnsbrn-has_many_polymorphs 2.13.1 → 2.13.3

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.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 3
3
3
  :major: 2
4
4
  :minor: 13
@@ -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:
@@ -144,6 +147,47 @@ class ActiveRecord::Base #:nodoc:
144
147
 
145
148
  find_by_sql(sql)
146
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
147
191
 
148
192
  def parse_tags(tags)
149
193
  return [] if tags.blank?
@@ -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
@@ -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
@@ -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: johnsbrn-has_many_polymorphs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.1
4
+ version: 2.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Weaver
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-25 00:00:00 -08:00
12
+ date: 2009-02-02 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -202,6 +202,8 @@ files:
202
202
  - test/integration/app/test/unit/single_sti_parent_test.rb
203
203
  - test/integration/app/test/unit/stick_test.rb
204
204
  - test/integration/app/test/unit/stone_test.rb
205
+ - test/integration/app/vendor
206
+ - test/integration/app/vendor/plugins
205
207
  - test/integration/server_test.rb
206
208
  - test/models
207
209
  - test/models/aquatic