louisville 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/louisville/extensions/history.rb +19 -2
- data/lib/louisville/util.rb +1 -0
- data/lib/louisville/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 778c590f3c4a13bf48ba4db2c3dd3c00c735ccb0
|
4
|
+
data.tar.gz: c07a7383e2455446acdf3e1d26bc00581047c803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0072d92faafc4a907f1624f05f53aea36c6af6b9a5c7d96d1853e717760c6955959c5c9fcb295a5775badc627052ae75a39f8632dc0d316b4b296808e7e7f29
|
7
|
+
data.tar.gz: e0d754e8baed79fcb6127a0b2d4087e602f2ea6a817e29b7caa2222e11224dececa83d27c18abb2cd7bfe7c474ed507ac1fb684a5ecd9018bacc556d7cf6dfe2
|
@@ -12,24 +12,41 @@ module Louisville
|
|
12
12
|
module Extensions
|
13
13
|
module History
|
14
14
|
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def historical_slug_sluggable_type
|
18
|
+
self.sti_name
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
15
23
|
|
16
24
|
def self.included(base)
|
17
25
|
base.class_eval do
|
18
26
|
|
19
|
-
|
20
|
-
has_many :historical_slugs, :class_name => 'Louisville::Slug', :dependent => :destroy, :as => :sluggable
|
27
|
+
extend ::Louisville::Extensions::History::ClassMethods
|
21
28
|
|
22
29
|
# If our slug has changed we should manage the history.
|
23
30
|
after_save :delete_matching_historical_slug, :if => :louisville_slug_changed?
|
24
31
|
after_save :generate_historical_slug, :if => :louisville_slug_changed?
|
32
|
+
|
33
|
+
before_destroy :destroy_historical_slugs!
|
25
34
|
end
|
26
35
|
end
|
27
36
|
|
37
|
+
def historical_slugs
|
38
|
+
return ::Louisville::Slug.where('1=0') unless persisted?
|
39
|
+
::Louisville::Slug.where(:sluggable_id => id, :sluggable_type => ::Louisville::Util.polymorphic_name(self.class))
|
40
|
+
end
|
28
41
|
|
29
42
|
|
30
43
|
protected
|
31
44
|
|
32
45
|
|
46
|
+
def destroy_historical_slugs!
|
47
|
+
historical_slugs.destroy_all
|
48
|
+
end
|
49
|
+
|
33
50
|
|
34
51
|
# First, we delete any previous slugs that this record owned that match the current slug.
|
35
52
|
# This allows a record to return to a previous slug without duplication in the history table.
|
data/lib/louisville/util.rb
CHANGED
data/lib/louisville/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: louisville
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|