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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdc680eb9ca340621494d36950a855275314f80a
4
- data.tar.gz: cdcd1db4119ae3ac44992ad07a9568f8ce1d1e6b
3
+ metadata.gz: 778c590f3c4a13bf48ba4db2c3dd3c00c735ccb0
4
+ data.tar.gz: c07a7383e2455446acdf3e1d26bc00581047c803
5
5
  SHA512:
6
- metadata.gz: 93640afde3565c61129849b03f5bae891c486f82b948335329f1dd1c4fa7a779cba16f4804dafcb6c659047e567eeb14181d49133870a87b635d73ae3825ae5b
7
- data.tar.gz: 0a5050f87c8db5e269acd3067b9f3741ac9470168b37c2c2c05051fa13266d81326c65bbffe278053f4d40ac98a688418d33b222a30bed9b6095bf1b4ceaf538
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
- # provide an association for easy lookup, joining, etc.
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.
@@ -30,6 +30,7 @@ module Louisville
30
30
 
31
31
 
32
32
  def polymorphic_name(klass)
33
+ return klass.historical_slug_sluggable_type if klass.respond_to?(:historical_slug_sluggable_type)
33
34
  klass.base_class.sti_name
34
35
  end
35
36
 
@@ -3,7 +3,7 @@ module Louisville
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- PATCH = 3
6
+ PATCH = 4
7
7
  PRE = nil
8
8
 
9
9
  def self.to_s
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.3
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-07 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord