friendly_id4 4.0.0.beta3 → 4.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/friendly_id.rb +18 -12
- data/lib/friendly_id/base.rb +18 -9
- data/lib/friendly_id/version.rb +1 -1
- data/test/base_test.rb +1 -1
- metadata +16 -16
data/lib/friendly_id.rb
CHANGED
@@ -14,21 +14,27 @@ module FriendlyId
|
|
14
14
|
autoload :History, "friendly_id/history"
|
15
15
|
|
16
16
|
# FriendlyId takes advantage of `extended` to do basic model setup, primarily
|
17
|
-
# extending FriendlyId::Base to add #friendly_id
|
18
|
-
#
|
19
|
-
# this library, ActiveRecord::Base was patched by default to include methods
|
20
|
-
# needed to configure friendly_id, but this version tries to be a little less
|
21
|
-
# invasive.
|
17
|
+
# extending {FriendlyId::Base} to add {FriendlyId::Base#friendly_id
|
18
|
+
# friendly_id} as a class method.
|
22
19
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
20
|
+
# Previous versions of FriendlyId simply patched ActiveRecord::Base, but this
|
21
|
+
# version tries to be less invasive.
|
22
|
+
#
|
23
|
+
# In addition to adding {FriendlyId::Base.friendly_id friendly_id}, the class
|
24
|
+
# instance variable +@friendly_id_config+ is added. This variable is an
|
25
|
+
# instance of an anonymous subclass of {FriendlyId::Configuration}. This
|
26
|
+
# allows subsequently loaded modules like {FriendlyId::Slugged} and
|
27
|
+
# {FriendlyId::Scoped} to add functionality to the configuration class only
|
28
|
+
# for the current class, rather than monkey patching
|
29
|
+
# {FriendlyId::Configuration} directly. This isolates other models from large
|
30
|
+
# feature changes an addon to FriendlyId could potentially introduce.
|
31
|
+
#
|
32
|
+
# The upshot of this is, you can htwo Active Record models that both have a
|
30
33
|
# @friendly_id_config, but each config object can have different methods and
|
31
34
|
# behaviors depending on what modules have been loaded, without conflicts.
|
35
|
+
# Keep this in mind if you're hacking on FriendlyId.
|
36
|
+
#
|
37
|
+
# For examples of this, see the source for {Scoped.included}.
|
32
38
|
def self.extended(base)
|
33
39
|
base.instance_eval do
|
34
40
|
extend FriendlyId::Base
|
data/lib/friendly_id/base.rb
CHANGED
@@ -2,15 +2,24 @@ module FriendlyId
|
|
2
2
|
# Class methods that will be added to ActiveRecord::Base.
|
3
3
|
module Base
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
# Configure FriendlyId for a model. Use this method to configure FriendlyId
|
6
|
+
# for your model.
|
7
|
+
#
|
8
|
+
# class Post < ActiveRecord::Base
|
9
|
+
# extend FriendlyId
|
10
|
+
# friendly_id :title, :use => :slugged
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# @option options [Symbol] :use The name of an addon to use. By default, FriendlyId
|
14
|
+
# provides {FriendlyId::Slugged :slugged}, {FriendlyId::History :history}
|
15
|
+
# and {FriendlyId::Scoped :scoped}.
|
16
|
+
# @option options [Symbol] :slug_column Available when using +:slugged+.
|
17
|
+
# Configures the name of the column where FriendlyId will store the slug.
|
18
|
+
# Defaults to +:slug+.
|
19
|
+
def friendly_id(base = nil, options = {}, &block)
|
20
|
+
@friendly_id_config.use options.delete :use
|
21
|
+
@friendly_id_config.send :set, options.merge(:base => base)
|
22
|
+
yield @friendly_id_config if block_given?
|
14
23
|
before_save do |record|
|
15
24
|
record.instance_eval {@current_friendly_id = friendly_id}
|
16
25
|
end
|
data/lib/friendly_id/version.rb
CHANGED
data/test/base_test.rb
CHANGED
@@ -17,7 +17,7 @@ class CoreTest < MiniTest::Unit::TestCase
|
|
17
17
|
test "friendly_id should accept a block" do
|
18
18
|
klass = Class.new(ActiveRecord::Base) do
|
19
19
|
extend FriendlyId
|
20
|
-
friendly_id do |config|
|
20
|
+
friendly_id :foo do |config|
|
21
21
|
config.use :slugged
|
22
22
|
config.base = :foo
|
23
23
|
config.slug_column = :bar
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_id4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.beta4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-29 00:00:00.000000000 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &70126503605200 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70126503605200
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &70126503604500 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70126503604500
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: cutest
|
39
|
-
requirement: &
|
39
|
+
requirement: &70126503603900 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.1.2
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70126503603900
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: ffaker
|
50
|
-
requirement: &
|
50
|
+
requirement: &70126503603440 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70126503603440
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: maruku
|
61
|
-
requirement: &
|
61
|
+
requirement: &70126503602760 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70126503602760
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: yard
|
72
|
-
requirement: &
|
72
|
+
requirement: &70126503602100 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70126503602100
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: mocha
|
83
|
-
requirement: &
|
83
|
+
requirement: &70126503601460 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70126503601460
|
92
92
|
description: ! " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink
|
93
93
|
plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n
|
94
94
|
\ human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
|