friendly_id 5.0.0.rc2 → 5.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/Changelog.md +13 -0
- data/bench.rb +3 -4
- data/gemfiles/Gemfile.rails-stable.rb +24 -0
- data/lib/friendly_id/base.rb +1 -1
- data/lib/friendly_id/configuration.rb +7 -3
- data/lib/friendly_id/finders.rb +9 -3
- data/lib/friendly_id/history.rb +10 -12
- data/lib/friendly_id/scoped.rb +1 -1
- data/lib/friendly_id/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc160c133d04de411d380863dcb8f5f6bf3d3eb
|
4
|
+
data.tar.gz: 69989b70207313b3895dcb250dd28b9a5dd52503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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;
|
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;
|
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
|
data/lib/friendly_id/base.rb
CHANGED
@@ -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(
|
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
|
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
|
|
data/lib/friendly_id/finders.rb
CHANGED
@@ -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.
|
55
|
+
model_class.instance_eval do
|
56
|
+
relation.class.send(:include, friendly_id_config.finder_methods)
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
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
|
data/lib/friendly_id/history.rb
CHANGED
@@ -55,7 +55,13 @@ method.
|
|
55
55
|
module History
|
56
56
|
|
57
57
|
def self.setup(model_class)
|
58
|
-
model_class.
|
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
|
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)).
|
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)
|
data/lib/friendly_id/scoped.rb
CHANGED
@@ -69,7 +69,7 @@ relation:
|
|
69
69
|
|
70
70
|
Alternatively, you could pass the scope value as a query parameter:
|
71
71
|
|
72
|
-
Restaurant.
|
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
|
data/lib/friendly_id/version.rb
CHANGED
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.
|
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-
|
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
|