vidibus-permalink 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ class Permalink
10
10
  field :scope, :type => Array
11
11
  field :_current, :type => Boolean, :default => true
12
12
 
13
+ before_validation :sanitize_value!
13
14
  after_save :unset_other_current, :if => :current?
14
15
  after_destroy :set_last_current, :if => :current?
15
16
 
@@ -37,17 +38,15 @@ class Permalink
37
38
  end
38
39
  end
39
40
 
40
- # Assigns given string as value.
41
41
  # Sanitizes and increments string, if necessary.
42
- def value=(string)
43
- unless string == value
44
- string = sanitize(string)
45
- unless string == value
46
- string = increment(string)
47
- self.write_attribute(:value, string)
48
- end
42
+ def sanitize_value!
43
+ return true unless value_changed? || new_record?
44
+ string = sanitize(value)
45
+ if string != value_was
46
+ string = increment(string)
49
47
  end
50
- string
48
+ self.value = string
49
+ true
51
50
  end
52
51
 
53
52
  def scope=(scope)
@@ -157,7 +156,8 @@ class Permalink
157
156
  # Finds existing permalinks with current value.
158
157
  def existing(string)
159
158
  @existing ||= {}
160
- @existing[string] ||= Permalink.where(:value => /^#{string}(-\d+)?$/).excludes(:_id => id).to_a
159
+ @existing[string] ||=
160
+ Permalink.for_scope(scope).where(:value => /^#{string}(-\d+)?$/).excludes(:_id => id).to_a
161
161
  end
162
162
 
163
163
  # Sets _current to false on all permalinks of the assigned linkable.
@@ -9,10 +9,12 @@ module Vidibus
9
9
  field :permalink, :type => String
10
10
  index :permalink
11
11
 
12
- before_validation :set_permalink
13
- validates :permalink, :presence => true
12
+ attr_accessor :skip_permalink
14
13
 
15
- after_save :store_permalink_object
14
+ before_validation :set_permalink, :unless => :skip_permalink
15
+ validates :permalink, :presence => true, :unless => :skip_permalink
16
+
17
+ after_save :store_permalink_object, :unless => :skip_permalink
16
18
  after_destroy :destroy_permalink_objects
17
19
  end
18
20
 
@@ -42,7 +44,8 @@ module Vidibus
42
44
 
43
45
  # Returns the current permalink object.
44
46
  def permalink_object
45
- @permalink_object || permalink_repository.for_linkable(self).where(:_current => true).first if permalink_repository
47
+ @permalink_object ||
48
+ permalink_repository.for_linkable(self).where(:_current => true).first if permalink_repository
46
49
  end
47
50
 
48
51
  # Returns all permalink objects ordered by time of update.
@@ -101,6 +104,7 @@ module Vidibus
101
104
  value = values.join(" ")
102
105
  if permalink_repository
103
106
  @permalink_object = permalink_object_by_value(value)
107
+ @permalink_object.sanitize_value!
104
108
  @permalink_object.current!
105
109
  self.permalink = @permalink_object.value
106
110
  else
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Permalink
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-permalink
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-06 00:00:00 +02:00
18
+ date: 2011-09-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency