friendly_id4 4.0.0.beta6 → 4.0.0.pre

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.
metadata CHANGED
@@ -1,165 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: friendly_id4
3
- version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta6
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease: 6
5
+ version: 4.0.0.pre
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Norman Clarke
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-11 00:00:00.000000000 -03:00
12
+
13
+ date: 2011-06-08 00:00:00 -03:00
13
14
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
16
17
  name: activerecord
17
- requirement: &70168979272700 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '3.0'
23
- type: :development
24
18
  prerelease: false
25
- version_requirements: *70168979272700
26
- - !ruby/object:Gem::Dependency
27
- name: sqlite3
28
- requirement: &70168979272160 !ruby/object:Gem::Requirement
19
+ requirement: &id001 !ruby/object:Gem::Requirement
29
20
  none: false
30
- requirements:
21
+ requirements:
31
22
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1.3'
23
+ - !ruby/object:Gem::Version
24
+ version: "3.0"
34
25
  type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
35
29
  prerelease: false
36
- version_requirements: *70168979272160
37
- - !ruby/object:Gem::Dependency
38
- name: cutest
39
- requirement: &70168979271700 !ruby/object:Gem::Requirement
30
+ requirement: &id002 !ruby/object:Gem::Requirement
40
31
  none: false
41
- requirements:
32
+ requirements:
42
33
  - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 1.1.2
45
- type: :development
46
- prerelease: false
47
- version_requirements: *70168979271700
48
- - !ruby/object:Gem::Dependency
49
- name: ffaker
50
- requirement: &70168979271300 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: *70168979271300
59
- - !ruby/object:Gem::Dependency
60
- name: maruku
61
- requirement: &70168979270840 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
67
- type: :development
68
- prerelease: false
69
- version_requirements: *70168979270840
70
- - !ruby/object:Gem::Dependency
71
- name: yard
72
- requirement: &70168979270420 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
34
+ - !ruby/object:Gem::Version
35
+ version: "0.9"
78
36
  type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: sqlite3
79
40
  prerelease: false
80
- version_requirements: *70168979270420
81
- - !ruby/object:Gem::Dependency
82
- name: mocha
83
- requirement: &70168979270000 !ruby/object:Gem::Requirement
41
+ requirement: &id003 !ruby/object:Gem::Requirement
84
42
  none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: "1.3"
89
47
  type: :development
90
- prerelease: false
91
- version_requirements: *70168979270000
92
- description: ! " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink
93
- plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n
94
- \ human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
95
- email:
96
- - norman@njclarke.com
48
+ version_requirements: *id003
49
+ description: " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
50
+ email: norman@njclarke.com
97
51
  executables: []
52
+
98
53
  extensions: []
54
+
99
55
  extra_rdoc_files: []
100
- files:
101
- - .gemtest
102
- - .gitignore
103
- - .yardopts
104
- - Gemfile
105
- - README.md
106
- - Rakefile
107
- - WhatsNew.md
108
- - bench.rb
109
- - friendly_id.gemspec
110
- - lib/friendly_id.rb
111
- - lib/friendly_id/base.rb
112
- - lib/friendly_id/configuration.rb
113
- - lib/friendly_id/finder_methods.rb
114
- - lib/friendly_id/history.rb
115
- - lib/friendly_id/migration.rb
116
- - lib/friendly_id/model.rb
117
- - lib/friendly_id/object_utils.rb
118
- - lib/friendly_id/reserved.rb
56
+
57
+ files:
119
58
  - lib/friendly_id/scoped.rb
120
- - lib/friendly_id/slug.rb
121
- - lib/friendly_id/slug_sequencer.rb
122
59
  - lib/friendly_id/slugged.rb
123
- - lib/generators/friendly_id_generator.rb
124
- - test/base_test.rb
125
- - test/config/mysql.yml
126
- - test/config/mysql2.yml
127
- - test/config/postgres.yml
128
- - test/config/sqlite3.yml
129
- - test/configuration_test.rb
60
+ - lib/friendly_id/test/generic.rb
61
+ - lib/friendly_id/test.rb
62
+ - lib/friendly_id/version.rb
63
+ - lib/friendly_id.rb
64
+ - README.md
65
+ - Rakefile
130
66
  - test/core_test.rb
131
- - test/helper.rb
132
- - test/history_test.rb
133
- - test/object_utils_test.rb
134
- - test/reserved_test.rb
135
- - test/schema.rb
136
67
  - test/scoped_test.rb
137
- - test/shared.rb
138
68
  - test/slugged_test.rb
139
- - test/sti_test.rb
69
+ - test/test_helper.rb
140
70
  has_rdoc: true
141
- homepage: http://norman.github.com/friendly_id
71
+ homepage: http://norman.github.com/friendly_id_4
142
72
  licenses: []
73
+
143
74
  post_install_message:
144
75
  rdoc_options: []
145
- require_paths:
76
+
77
+ require_paths:
146
78
  - lib
147
- required_ruby_version: !ruby/object:Gem::Requirement
79
+ required_ruby_version: !ruby/object:Gem::Requirement
148
80
  none: false
149
- requirements:
150
- - - ! '>='
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
86
  none: false
155
- requirements:
156
- - - ! '>'
157
- - !ruby/object:Gem::Version
87
+ requirements:
88
+ - - ">"
89
+ - !ruby/object:Gem::Version
158
90
  version: 1.3.1
159
91
  requirements: []
160
- rubyforge_project: friendly_id
161
- rubygems_version: 1.6.2
92
+
93
+ rubyforge_project: friendly-id
94
+ rubygems_version: 1.6.1
162
95
  signing_key:
163
96
  specification_version: 3
164
97
  summary: A comprehensive slugging and pretty-URL plugin.
165
- test_files: []
98
+ test_files:
99
+ - test/core_test.rb
100
+ - test/scoped_test.rb
101
+ - test/slugged_test.rb
data/.gemtest DELETED
File without changes
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- Gemfile
2
- Gemfile.lock
3
- doc
4
- docs
5
- pkg
6
- .DS_Store
7
- coverage
8
- .yardoc
9
- *.gem
10
- *.sqlite3
11
- *.rbc
data/.yardopts DELETED
@@ -1,4 +0,0 @@
1
- --files=*.md
2
- --protected
3
- --list-undoc
4
- --exclude lib/friendly_id/migration
@@ -1,142 +0,0 @@
1
- # What's new in FriendlyId 4.0?
2
-
3
- This is a rewrite/rethink of FriendlyId. It will probably be released some time
4
- in August or September 2011, once I've had the chance to actually use it in a
5
- real website for a while.
6
-
7
- It's probably not wise to use this on a real site right now unless you're
8
- comfortable with the source code and willing to fix bugs that will likely occur.
9
-
10
- That said, I will soon be deploying this on a high-traffic, production site, so
11
- I have a personal stake in making this work well. Your feedback is most welcome.
12
-
13
- If you want to try it out, grab the source, or [install the
14
- gem](https://rubygems.org/gems/friendly_id4).
15
-
16
- ## Back to basics
17
-
18
- This isn't the "big rewrite," it's the "small rewrite."
19
-
20
- Adding new features with each release is not sustainable. This release *removes*
21
- features, but makes it possible to add them back as addons. We can also remove
22
- some complexity by relying on the better default functionality provided by newer
23
- versions of Active Support and Active Record. Let's see how small we can make
24
- this!
25
-
26
- Here's what's changed:
27
-
28
- ## Active Record 3+ only
29
-
30
- For 2.3 support, you can use FriendlyId 3, which will continue to be maintained
31
- until people don't want it any more.
32
-
33
- ## In-table slugs
34
-
35
- FriendlyId no longer creates a separate slugs table - it just stores the
36
- generated slug value in the model table, which is simpler, faster and what most
37
- people seem to want. Keeping slug history in a separate table is an optional
38
- add-on for FriendlyId 4.
39
-
40
- ## No more multiple finds
41
-
42
- Person.find "joe-schmoe" # Supported
43
- Person.find ["joe-schmoe", "john-doe"] # No longer supported
44
-
45
- If you want find by more than one friendly id, build your own query:
46
-
47
- Person.where(:slug => ["joe-schmoe", "john-doe"])
48
-
49
- This lets us do *far* less monkeypatching in Active Record. How much less?
50
- FriendlyId overrides the base find with a mere 2 lines of code, and otherwise
51
- changes nothing else. This means more stability and less breakage between Rails
52
- updates.
53
-
54
- ## No more finder status
55
-
56
- FriendlyId 3 offered finder statuses to help you determine when an outdated
57
- or non-friendly id was used to find the record, so that you could decide whether
58
- to permanently redirect to the canonical URL. However, there's a simpler way to
59
- do that, so this feature has been removed:
60
-
61
- if request.path != person_path(@person)
62
- return redirect_to @person, :status => :moved_permanently
63
- end
64
-
65
- ## No more slug history - unless you want it
66
-
67
- Since slugs are now stored in-table, when you update them, finds for the
68
- previous slug will no longer work. This can be a problem for permalinks, since
69
- renaming a friendly_id will lead to 404's.
70
-
71
- This was transparently handled by FriendlyId 3, but there were three problems:
72
-
73
- * Not everybody wants or needs this
74
- * Performance was negatively affected
75
- * Determining whether a current or old id was used was expensive, clunky, and
76
- inconsistent when finding inside relations.
77
-
78
- Here's how to do this in FriendlyId 4:
79
-
80
- class PostsController < ApplicationController
81
-
82
- before_filter :find_post
83
-
84
- ...
85
-
86
- def find_post
87
- return unless params[:id]
88
- @post = begin
89
- Post.find params[:id]
90
- rescue ActiveRecord::RecordNotFound
91
- Post.find_by_friendly_id params[:id]
92
- end
93
- # If an old id or a numeric id was used to find the record, then
94
- # the request path will not match the post_path, and we should do
95
- # a 301 redirect that uses the current friendly_id
96
- if request.path != post_path(@post)
97
- return redirect_to @post, :status => :moved_permanently
98
- end
99
- end
100
-
101
- Under FriendlyId 4 this is a little more verbose, but offers much finer-grained
102
- control over the finding process, performs better, and has a much simpler
103
- implementation.
104
-
105
- ## "Reserved words" are now just a normal validation
106
-
107
- Rather than use a custom reserved words validator, use the validations provided
108
- by Active Record. FriendlyId still reserves "new" and "edit" by default to avoid
109
- routing problems.
110
-
111
- validates_exclusion_of :name, :in => ["bad", "word"]
112
-
113
- You can configure the default words reserved by FriendlyId in
114
- `FriendlyId::Configuration::DEFAULTS[:reserved_words]`.
115
-
116
- ## "Allow nil" is now just another validation
117
-
118
- Previous versions of FriendlyId offered a special option to allow nil slug
119
- values, but this is now the default. If you don't want this, then simply add a
120
- validation to the slug column, and/or declare the column `NOT NULL` in your
121
- database.
122
-
123
- ## Bye-bye Babosa
124
-
125
- [Babosa](http://github.com/norman/babosa) is FriendlyId 3's slugging library.
126
-
127
- FriendlyId 4 doesn't use it by default because the most important pieces of it
128
- were already accepted into Active Support 3.
129
-
130
- However, Babosa is still useful, for example, for idiomatically transliterating
131
- Cyrillic ([or other
132
- language](https://github.com/norman/babosa/tree/master/lib/babosa/transliterator))
133
- strings to ASCII. It's very easy to include - just override
134
- `#normalize_friendly_id` in your model:
135
-
136
- class MyModel < ActiveRecord::Base
137
- ...
138
-
139
- def normalize_friendly_id(text)
140
- text.to_slug.normalize! :transliterate => :russian
141
- end
142
- end
data/bench.rb DELETED
@@ -1,63 +0,0 @@
1
- require File.expand_path("../test/helper", __FILE__)
2
- require "ffaker"
3
-
4
- N = 1000
5
-
6
- def transaction
7
- ActiveRecord::Base.transaction { yield ; raise ActiveRecord::Rollback }
8
- end
9
-
10
- class Array
11
- def rand
12
- self[Kernel.rand(length)]
13
- end
14
- end
15
-
16
- Book = Class.new ActiveRecord::Base
17
-
18
- class Journalist < ActiveRecord::Base
19
- extend FriendlyId
20
- include FriendlyId::Slugged
21
- friendly_id :name
22
- end
23
-
24
- class Manual < ActiveRecord::Base
25
- extend FriendlyId
26
- include FriendlyId::History
27
- friendly_id :name
28
- end
29
-
30
- BOOKS = []
31
- JOURNALISTS = []
32
- MANUALS = []
33
-
34
- 100.times do
35
- name = Faker::Name.name
36
- BOOKS << (Book.create! :name => name).id
37
- JOURNALISTS << (Journalist.create! :name => name).friendly_id
38
- MANUALS << (Manual.create! :name => name).friendly_id
39
- end
40
-
41
- Benchmark.bmbm do |x|
42
- x.report 'find (without FriendlyId)' do
43
- N.times {Book.find BOOKS.rand}
44
- end
45
- x.report 'find (in-table slug)' do
46
- N.times {Journalist.find JOURNALISTS.rand}
47
- end
48
- x.report 'find (external slug)' do
49
- N.times {Manual.find_by_friendly_id MANUALS.rand}
50
- end
51
-
52
- x.report 'insert (without FriendlyId)' do
53
- N.times {transaction {Book.create :name => Faker::Name.name}}
54
- end
55
-
56
- x.report 'insert (in-table-slug)' do
57
- N.times {transaction {Journalist.create :name => Faker::Name.name}}
58
- end
59
-
60
- x.report 'insert (external slug)' do
61
- N.times {transaction {Manual.create :name => Faker::Name.name}}
62
- end
63
- end