slugs 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9df30988555a045bd418b90aa72fa57b6a87549f
4
- data.tar.gz: 5d02fbdec96cab05fb92f14a7092072c69435155
3
+ metadata.gz: aecbeea315d4b4db2d895b00469e2a38182fdd6a
4
+ data.tar.gz: 70ba94e82740be45d7e55ee9d1446fafc5cd06b3
5
5
  SHA512:
6
- metadata.gz: 8aea2da8d1ac5cd6b659d14e7752d8ca1ebfcece335ae492f924675de281660c24794dd4f2901a945a92fecc3b270f95d2226afc619b68bf767fa9a0d9cd8d58
7
- data.tar.gz: 94d95f8c93a02e70d9b13010e89cbe8398660bc877d69f1f8ca5b73902ac7f5da1c7aea595d574f274df0029a0178484a8bceb3f02aadf3cc002e1fae226eef1
6
+ metadata.gz: 2ee46e927cab1a0caaafb8f3d50f9b849d9967a8e021aa433eea986df07380cfac89126b786976a210079f02a2d7f3e0f898d6885d35d73dc117f9322bbaeb86
7
+ data.tar.gz: 566f8b8a896fd6bc4741e698c03b59149aee1eba08638159e57db08c7e580e9a9cf4d22a276de8003fdc063e6e7aa36ee57d7e8b0facae64d66f5638ef5bf067
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Museways
1
+ Copyright 2015 Museways
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -49,15 +49,12 @@ If you need a very custom slug you can use a lambda, proc or block:
49
49
  has_slug proc { |record| "#{record.prop}-custom" }
50
50
  ```
51
51
 
52
- Then the find method of your models will accept slugs and ids transparently:
52
+ To find a record by slug:
53
53
  ```ruby
54
- Model.find 'slug'
54
+ Model.slugged.find 'slug'
55
55
  ```
56
56
 
57
- All the path and url helpers will start using the slug by default if you want to force the id:
58
- ```ruby
59
- model_path(instance.id)
60
- ```
57
+ NOTE: All the path and url helpers will start using the slug by default.
61
58
 
62
59
  ## Credits
63
60
 
@@ -4,7 +4,15 @@ module Slugs
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  def to_param
7
- self.class.sluggable? ? (slug_changed? ? slug_was : slug) : super
7
+ if self.class.sluggable?
8
+ if slug_changed?
9
+ slug_was
10
+ else
11
+ slug
12
+ end
13
+ else
14
+ super
15
+ end
8
16
  end
9
17
 
10
18
  protected
@@ -51,7 +59,7 @@ module Slugs
51
59
 
52
60
  def has_slug(*args, &block)
53
61
  unless sluggable?
54
- if respond_to? :translatable? and translatable?
62
+ if try(:translatable?)
55
63
  include Slugs::ActiveRecord::Translatable
56
64
  attr_translatable :slug
57
65
  before_validation :generate_slugs
@@ -59,6 +67,7 @@ module Slugs
59
67
  include Slugs::ActiveRecord::NonTranslatable
60
68
  before_validation :generate_slug
61
69
  end
70
+ include Slugs::ActiveRecord::Finders
62
71
  if block_given?
63
72
  self.slug = block
64
73
  else
@@ -0,0 +1,24 @@
1
+ module Slugs
2
+ module ActiveRecord
3
+ module Finders
4
+ extend ActiveSupport::Concern
5
+ module ClassMethods
6
+
7
+ def slugged
8
+ all.extending do
9
+
10
+ def find(*args)
11
+ find_by_slug args.first
12
+ end
13
+
14
+ def exists?(*args)
15
+ exists_by_slug? args.first
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -4,10 +4,6 @@ module Slugs
4
4
  extend ActiveSupport::Concern
5
5
  module ClassMethods
6
6
 
7
- def exists_by_slug(id)
8
- exists? slug: id
9
- end
10
-
11
7
  def find_previous_slug(slug)
12
8
  where(
13
9
  'slug LIKE ? OR slug = ?', "#{slug}-%", slug
@@ -16,6 +12,14 @@ module Slugs
16
12
  ).map(&:slug).select{ |r| r =~ /^#{slug}(-\d+)?$/ }.first
17
13
  end
18
14
 
15
+ def find_by_slug(id)
16
+ find_by slug: id
17
+ end
18
+
19
+ def exists_by_slug?(id)
20
+ exists? slug: id
21
+ end
22
+
19
23
  end
20
24
  end
21
25
  end
@@ -38,7 +38,7 @@ module Slugs
38
38
  ).readonly(false).first
39
39
  end
40
40
 
41
- def exists_by_slug(id)
41
+ def exists_by_slug?(id)
42
42
  t = reflect_on_association(:translations)
43
43
  joins(:translations).exists? t.table_name.to_sym => { slug: id, locale: I18n.locale }
44
44
  end
data/lib/slugs/railtie.rb CHANGED
@@ -3,7 +3,6 @@ module Slugs
3
3
 
4
4
  initializer 'slugs' do
5
5
  ::ActiveRecord::Base.send :include, Slugs::ActiveRecord::Base
6
- ::ActiveRecord::Relation.send :include, Slugs::ActiveRecord::Relation
7
6
  end
8
7
 
9
8
  end
data/lib/slugs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Slugs
2
2
 
3
- VERSION = '1.2.5'
3
+ VERSION = '1.3.0'
4
4
 
5
5
  end
data/lib/slugs.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'slugs/active_record/base'
2
2
  require 'slugs/active_record/non_translatable'
3
3
  require 'slugs/active_record/translatable'
4
- require 'slugs/active_record/relation'
4
+ require 'slugs/active_record/finders'
5
5
  require 'slugs/railtie'
6
6
 
7
7
  module Slugs
@@ -20,7 +20,11 @@ Dummy::Application.configure do
20
20
  # config.action_dispatch.rack_cache = true
21
21
 
22
22
  # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_assets = false
23
+ if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
24
+ config.serve_static_files = false
25
+ else
26
+ config.serve_static_assets = false
27
+ end
24
28
 
25
29
  # Compress JavaScripts and CSS.
26
30
  config.assets.js_compressor = :uglifier
@@ -13,7 +13,11 @@ Dummy::Application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_assets = true
16
+ if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
17
+ config.serve_static_files = false
18
+ else
19
+ config.serve_static_assets = false
20
+ end
17
21
  config.static_cache_control = "public, max-age=3600"
18
22
 
19
23
  # Show full error reports and disable caching.
@@ -33,4 +37,8 @@ Dummy::Application.configure do
33
37
 
34
38
  # Print deprecation notices to the stderr.
35
39
  config.active_support.deprecation = :stderr
40
+
41
+ if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
42
+ config.active_support.test_order = :random
43
+ end
36
44
  end