friendly_id 2.3.4 → 3.0.0.beta1

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.
Files changed (47) hide show
  1. data/Changelog.md +10 -0
  2. data/Contributors.md +1 -0
  3. data/Guide.md +48 -4
  4. data/README.md +6 -4
  5. data/Rakefile +1 -1
  6. data/extras/extras.rb +1 -1
  7. data/generators/friendly_id/friendly_id_generator.rb +1 -1
  8. data/lib/friendly_id.rb +4 -6
  9. data/lib/friendly_id/{active_record2 → acktive_record}/configuration.rb +2 -2
  10. data/lib/friendly_id/{active_record2 → acktive_record}/finders.rb +24 -10
  11. data/lib/friendly_id/{active_record2 → acktive_record}/simple_model.rb +12 -50
  12. data/lib/friendly_id/acktive_record/slug.rb +66 -0
  13. data/lib/friendly_id/{active_record2 → acktive_record}/slugged_model.rb +9 -85
  14. data/lib/friendly_id/{active_record2 → acktive_record}/tasks.rb +5 -2
  15. data/lib/friendly_id/{active_record2 → acktive_record}/tasks/friendly_id.rake +1 -1
  16. data/lib/friendly_id/{active_record2.rb → active_record.rb} +18 -13
  17. data/lib/friendly_id/configuration.rb +11 -26
  18. data/lib/friendly_id/finders.rb +5 -3
  19. data/lib/friendly_id/slug_string.rb +11 -10
  20. data/lib/friendly_id/slugged.rb +11 -4
  21. data/lib/friendly_id/test.rb +46 -5
  22. data/lib/friendly_id/version.rb +5 -4
  23. data/lib/generators/friendly_id_generator.rb +32 -0
  24. data/rails/init.rb +1 -1
  25. data/test/{active_record2 → acktive_record}/basic_slugged_model_test.rb +3 -3
  26. data/test/{active_record2 → acktive_record}/cached_slug_test.rb +3 -3
  27. data/test/{active_record2 → acktive_record}/core.rb +1 -1
  28. data/test/{active_record2 → acktive_record}/custom_normalizer_test.rb +3 -3
  29. data/test/{active_record2 → acktive_record}/custom_table_name_test.rb +3 -3
  30. data/test/{active_record2 → acktive_record}/scoped_model_test.rb +2 -2
  31. data/test/{active_record2 → acktive_record}/simple_test.rb +4 -1
  32. data/test/{active_record2 → acktive_record}/slug_test.rb +0 -0
  33. data/test/{active_record2 → acktive_record}/slugged.rb +1 -1
  34. data/test/{active_record2 → acktive_record}/slugged_status_test.rb +1 -1
  35. data/test/{active_record2 → acktive_record}/sti_test.rb +3 -3
  36. data/test/{active_record2 → acktive_record}/support/database.mysql.yml +0 -0
  37. data/test/{active_record2 → acktive_record}/support/database.postgres.yml +0 -0
  38. data/test/{active_record2 → acktive_record}/support/database.sqlite3.yml +0 -0
  39. data/test/{active_record2 → acktive_record}/support/models.rb +5 -6
  40. data/test/{active_record2 → acktive_record}/tasks_test.rb +1 -1
  41. data/test/acktive_record/temp_test.rb +32 -0
  42. data/test/{active_record2 → acktive_record}/test_helper.rb +4 -10
  43. data/test/slug_string_test.rb +5 -1
  44. data/test/test_helper.rb +9 -3
  45. metadata +48 -44
  46. data/lib/friendly_id/active_record2/slug.rb +0 -111
  47. data/test/active_record2/deprecated_test.rb +0 -23
@@ -1,111 +0,0 @@
1
- module FriendlyId
2
- module ActiveRecord2
3
-
4
- module DeprecatedSlugMethods
5
- # @deprecated Please use String#parse_friendly_id
6
- def parse(string)
7
- warn("Slug#parse is deprecated and will be removed in FriendlyId 3.0. Please use String#parse_friendly_id.")
8
- string.to_s.parse_friendly_id
9
- end
10
-
11
- # @deprecated Please use SlugString#normalize.
12
- def normalize(slug_text)
13
- warn("Slug#normalize is deprecated and will be removed in FriendlyId 3.0. Please use SlugString#normalize.")
14
- raise BlankError if slug_text.blank?
15
- SlugString.new(slug_text.to_s).normalize.to_s
16
- end
17
-
18
- # @deprecated Please use SlugString#approximate_ascii."
19
- def strip_diacritics(string)
20
- warn("Slug#strip_diacritics is deprecated and will be removed in FriendlyId 3.0. Please use SlugString#approximate_ascii.")
21
- raise BlankError if string.blank?
22
- SlugString.new(string).approximate_ascii
23
- end
24
-
25
- # @deprecated Please use SlugString#to_ascii.
26
- def strip_non_ascii(string)
27
- warn("Slug#strip_non_ascii is deprecated and will be removed in FriendlyId 3.0. Please use SlugString#to_ascii.")
28
- raise BlankError if string.blank?
29
- SlugString.new(string).to_ascii
30
- end
31
-
32
- end
33
-
34
- end
35
-
36
- end
37
-
38
- # A Slug is a unique, human-friendly identifier for an ActiveRecord.
39
- class Slug < ::ActiveRecord::Base
40
-
41
- extend FriendlyId::ActiveRecord2::DeprecatedSlugMethods
42
-
43
- table_name = "slugs"
44
- belongs_to :sluggable, :polymorphic => true
45
- before_save :enable_name_reversion, :set_sequence
46
- validate :validate_name
47
- named_scope :similar_to, lambda {|slug| {:conditions => {
48
- :name => slug.name,
49
- :scope => slug.scope,
50
- :sluggable_type => slug.sluggable_type
51
- },
52
- :order => "sequence ASC"
53
- }
54
- }
55
-
56
- # Whether this slug is the most recent of its owner's slugs.
57
- def current?
58
- sluggable.slug == self
59
- end
60
-
61
- def outdated?
62
- !current?
63
- end
64
-
65
- # @deprecated Please used Slug#current?
66
- def is_most_recent?
67
- warn("Slug#is_most_recent? is deprecated and will be removed in FriendlyId 3.0. Please use Slug#current?")
68
- current?
69
- end
70
-
71
- def to_friendly_id
72
- sequence > 1 ? friendly_id_with_sequence : name
73
- end
74
-
75
- # Raise a FriendlyId::SlugGenerationError if the slug name is blank.
76
- def validate_name
77
- if name.blank?
78
- raise FriendlyId::BlankError.new("slug.name can not be blank.")
79
- end
80
- end
81
-
82
- private
83
-
84
- # If we're renaming back to a previously used friendly_id, delete the
85
- # slug so that we can recycle the name without having to use a sequence.
86
- def enable_name_reversion
87
- sluggable.slugs.find_all_by_name_and_scope(name, scope).each { |slug| slug.destroy }
88
- end
89
-
90
- def friendly_id_with_sequence
91
- "#{name}#{separator}#{sequence}"
92
- end
93
-
94
- def similar_to_other_slugs?
95
- !similar_slugs.empty?
96
- end
97
-
98
- def similar_slugs
99
- self.class.similar_to(self)
100
- end
101
-
102
- def separator
103
- sluggable.friendly_id_config.sequence_separator
104
- end
105
-
106
- def set_sequence
107
- return unless new_record?
108
- self.sequence = similar_slugs.last.sequence.succ if similar_to_other_slugs?
109
- end
110
-
111
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- module FriendlyId
4
- module Test
5
- module ActiveRecord2
6
-
7
- class DeprecatedTest < ::Test::Unit::TestCase
8
-
9
- include FriendlyId::Test::Generic
10
- include FriendlyId::Test::Slugged
11
- include FriendlyId::Test::ActiveRecord2::Slugged
12
- include FriendlyId::Test::ActiveRecord2::Core
13
-
14
- def klass
15
- Block
16
- end
17
-
18
- end
19
-
20
- end
21
- end
22
- end
23
-