friendly_id 5.0.0.rc2 → 5.0.0.rc3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b8e4a5f27bb5857aa5761f04a7300d96df81078
4
- data.tar.gz: 85674fed68afdc2ba0122cff6edb0424eeb3dcaa
3
+ metadata.gz: 2cc160c133d04de411d380863dcb8f5f6bf3d3eb
4
+ data.tar.gz: 69989b70207313b3895dcb250dd28b9a5dd52503
5
5
  SHA512:
6
- metadata.gz: 39e09066a6e62b4243e19f53c8640e15bfb05ed0c70fd4dbbfdfaf3cbb8aab162392e875ec79545e460ecdb716d2f8fd007c97a356963ccde9852b273216828c
7
- data.tar.gz: c1b52cbedd571df3644ce78a94b22df6a747b9b22d5d40bede443dcedd9f69c7ad6771f18e3183b1761f6ace0d512590767c349bafe75f9d5c209c537777cd7c
6
+ metadata.gz: 1de2c9b0aa51dca261d977bc4004d0f1d64e6f5f304e8e575ae2dc2c3e1fa1c24b780548729bd39685243f8190fa7fcf46de328f2d421b699c9e7fff75994d08
7
+ data.tar.gz: e5d920ae4b3eed5a1d93c747dc1d1ef5ff91e930cb85d93b22197bcbc1274c43d4f882b3f57d91c7afc11186e737eac8183643fbc9e31a6c10eb3ca5243202b2
data/.travis.yml CHANGED
@@ -1,15 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 1.9.3
5
- # - jruby-19mode
6
- # - rbx-19mode
7
4
  env:
8
5
  - DB=postgres
9
6
  - DB=mysql
10
7
  - DB=sqlite3
11
8
  gemfile:
12
9
  - gemfiles/Gemfile.rails-4.0.rb
10
+ - gemfiles/Gemfile.rails-stable.rb
13
11
 
14
12
  before_script: 'bundle exec rake db:create db:up'
15
13
  script: 'bundle exec rake test'
data/Changelog.md CHANGED
@@ -3,6 +3,19 @@
3
3
  We would like to think our many {file:Contributors contributors} for
4
4
  suggestions, ideas and improvements to FriendlyId.
5
5
 
6
+ ## 5.0.0.rc.3 (2013-10-04)
7
+
8
+ * Support friendly finds on associations in Rails 4.0.1 and up. They will
9
+ currently work on Rails 4.0 associations only if `:inverse_of` is not used.
10
+ In Rails 4-0-stable, associations have been modified to use a special
11
+ relation class, giving FriendlyId a consistent extension point. Since the
12
+ behavior in 4.0.0 is considered defective and fixed in 4-0-stable, FriendlyId
13
+ 5.0 will not support friendly finds on inverse relelations in 4.0.0. For a
14
+ reliable workaround, use the `friendly` scope for friendly finds on
15
+ associations; this works on all Rails 4.0.x versions and will continue to be
16
+ supported.
17
+ * Documentation fixes.
18
+
6
19
  ## 5.0.0.rc2 (2013-09-29)
7
20
 
8
21
  * When the :finders addon has been included, use it in FriendlyId's internal
data/bench.rb CHANGED
@@ -27,8 +27,7 @@ end
27
27
 
28
28
  class Restaurant < ActiveRecord::Base
29
29
  extend FriendlyId
30
- relation.class.send(:include, FriendlyId::FinderMethods)
31
- friendly_id :name
30
+ friendly_id :name, :use => :finders
32
31
  end
33
32
 
34
33
 
@@ -56,7 +55,7 @@ Benchmark.bmbm do |x|
56
55
  N.times {Journalist.friendly.find JOURNALISTS.rand}
57
56
  end
58
57
 
59
- x.report 'find (in-table slug; included FinderMethods)' do
58
+ x.report 'find (in-table slug; using finders module)' do
60
59
  N.times {Restaurant.find RESTAURANTS.rand}
61
60
  end
62
61
 
@@ -72,7 +71,7 @@ Benchmark.bmbm do |x|
72
71
  N.times {transaction {Journalist.create :name => Faker::Name.name}}
73
72
  end
74
73
 
75
- x.report 'insert (in-table-slug; included FinderMethods)' do
74
+ x.report 'insert (in-table-slug; using finders module)' do
76
75
  N.times {transaction {Restaurant.create :name => Faker::Name.name}}
77
76
  end
78
77
 
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'rails', github: 'rails/rails', branch: '4-0-stable' do
6
+ gem 'activerecord'
7
+ gem 'railties'
8
+ end
9
+
10
+ # Database Configuration
11
+ group :development, :test do
12
+ platforms :jruby do
13
+ gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0.beta2'
14
+ gem 'activerecord-jdbcmysql-adapter', '>= 1.3.0.beta2'
15
+ gem 'activerecord-jdbcpostgresql-adapter', '>= 1.3.0.beta2'
16
+ gem 'jruby-openssl'
17
+ end
18
+
19
+ platforms :ruby do
20
+ gem 'sqlite3'
21
+ gem 'mysql2'
22
+ gem 'pg'
23
+ end
24
+ end
@@ -203,7 +203,7 @@ often better and easier to use {FriendlyId::Slugged slugs}.
203
203
  # and maintainability. If you'd like to improve the performance, your
204
204
  # efforts would be best directed at improving it at the root cause
205
205
  # of the problem - in Rails - because it would benefit more people.
206
- all.extending(FinderMethods)
206
+ all.extending(friendly_id_config.finder_methods)
207
207
  end
208
208
 
209
209
  # Returns the model class's {FriendlyId::Configuration friendly_id_config}.
@@ -15,10 +15,14 @@ module FriendlyId
15
15
  # @return ActiveRecord::Base
16
16
  attr_accessor :model_class
17
17
 
18
+ # The module to use for finders
19
+ attr_accessor :finder_methods
20
+
18
21
  def initialize(model_class, values = nil)
19
- @model_class = model_class
20
- @defaults = {}
21
- @modules = []
22
+ @model_class = model_class
23
+ @defaults = {}
24
+ @modules = []
25
+ @finder_methods = FriendlyId::FinderMethods
22
26
  set values
23
27
  end
24
28
 
@@ -52,10 +52,16 @@ in your controllers to use the `friendly` scope. For example:
52
52
  =end
53
53
  module Finders
54
54
  def self.included(model_class)
55
- model_class.send(:relation).class.send(:include, FriendlyId::FinderMethods)
55
+ model_class.instance_eval do
56
+ relation.class.send(:include, friendly_id_config.finder_methods)
57
+ end
56
58
 
57
- if model_class.friendly_id_config.uses? :history
58
- model_class.send(:relation).class.send(:include, FriendlyId::History::HistoryFinderMethods)
59
+ # Support for friendly finds on associations for Rails 4.0.1 and above.
60
+ # As of 1 October 2013 this works on Rails 4-0-stable, but may change.
61
+ if ::ActiveRecord.const_defined?('AssociationRelation')
62
+ assocation_relation_class_name = :"ActiveRecord_AssociationRelation_#{model_class.to_s.gsub('::', '_')}"
63
+ association_relation_class = ::ActiveRecord::AssociationRelation.const_get(assocation_relation_class_name)
64
+ association_relation_class.send(:include, model_class.friendly_id_config.finder_methods)
59
65
  end
60
66
  end
61
67
  end
@@ -55,7 +55,13 @@ method.
55
55
  module History
56
56
 
57
57
  def self.setup(model_class)
58
- model_class.friendly_id_config.use :slugged
58
+ model_class.instance_eval do
59
+ friendly_id_config.use :slugged
60
+ friendly_id_config.finder_methods = FriendlyId::History::FinderMethods
61
+ if friendly_id_config.uses? :finders
62
+ relation.class.send(:include, friendly_id_config.finder_methods)
63
+ end
64
+ end
59
65
  end
60
66
 
61
67
  # Configures the model instance to use the History add-on.
@@ -67,20 +73,12 @@ method.
67
73
  :class_name => Slug.to_s
68
74
  }
69
75
 
70
- if model_class.friendly_id_config.uses? :finders
71
- model_class.send(:relation).class.send(:include, HistoryFinderMethods)
72
- end
73
-
74
76
  after_save :create_slug
75
-
76
- def self.friendly
77
- all.extending(HistoryFinderMethods)
78
- end
79
77
  end
80
78
  end
81
79
 
82
- module HistoryFinderMethods
83
- include FinderMethods
80
+ module FinderMethods
81
+ include ::FriendlyId::FinderMethods
84
82
 
85
83
  def exists_by_friendly_id?(id)
86
84
  joins(:slugs).where(arel_table[friendly_id_config.query_field].eq(id).or(slug_history_clause(id))).exists?
@@ -89,7 +87,7 @@ method.
89
87
  private
90
88
 
91
89
  def first_by_friendly_id(id)
92
- joins(:slugs).where(slug_history_clause(id)).readonly(false).first
90
+ select(quoted_table_name + '.*').joins(:slugs).where(slug_history_clause(id)).first
93
91
  end
94
92
 
95
93
  def slug_history_clause(id)
@@ -69,7 +69,7 @@ relation:
69
69
 
70
70
  Alternatively, you could pass the scope value as a query parameter:
71
71
 
72
- Restaurant.friendly.find("joes-diner").where(:city_id => @city.id)
72
+ Restaurant.where(:city_id => @city.id).friendly.find("joes-diner")
73
73
 
74
74
 
75
75
  ### Finding All Records That Match a Scoped ID
@@ -1,3 +1,3 @@
1
1
  module FriendlyId
2
- VERSION = "5.0.0.rc2"
2
+ VERSION = "5.0.0.rc3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc2
4
+ version: 5.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norman Clarke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-29 00:00:00.000000000 Z
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -161,6 +161,7 @@ files:
161
161
  - bench.rb
162
162
  - friendly_id.gemspec
163
163
  - gemfiles/Gemfile.rails-4.0.rb
164
+ - gemfiles/Gemfile.rails-stable.rb
164
165
  - guide.rb
165
166
  - lib/friendly_id.rb
166
167
  - lib/friendly_id/.gitattributes