simplec 0.8.0 → 0.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60e1f58d4c9b9f14e5f5b351649420083c35e457
4
- data.tar.gz: f5242acb988463f804efdb1b9707cfd8a1c1011b
3
+ metadata.gz: 9dee3744e8854330cbcf79ae6c9f2495c342a02e
4
+ data.tar.gz: ff0bceb7a5930bee2c635b0cc9d46076ee70bc99
5
5
  SHA512:
6
- metadata.gz: 449575640f16da976384986804fc3906cbd5ce3558a1b3928d8ebefb05ae0f9a4b8e34473218301deb1fa7ea8d249dab28247fab300df94a8a096ef2d8368684
7
- data.tar.gz: bc82948bcc1feb8e4715bb774b7b2f1957e2a1e3e2db855147c216860647cb3d06a791cd3f7403a42d847c4aae3c4bdcef1e7989564c02ccfc552226f563a0ea
6
+ metadata.gz: d93a2f80baa72c5db2973d063d4246c9eac0bf218be65576be8b9162733e6188cd74b85240418cc72acd40d7df426ea01f802d7e9e277c5087fd294175a59a66
7
+ data.tar.gz: 0bd3858809d3d3587920e1989e879f37e5fcdca6fcc4bce2b556f0a5fc5041e8e0b5a67ce25e6b7f9c318b8e8654e0effef128b61be40834cb643970ad781744
@@ -16,6 +16,14 @@ module Simplec
16
16
  self.file.url
17
17
  end
18
18
 
19
+ # @!visibility private
20
+ module Normalizers
21
+ def slug=(val)
22
+ super val.blank? ? nil : val
23
+ end
24
+ end
25
+ prepend Normalizers
26
+
19
27
  private
20
28
 
21
29
  def validate_subdomain_or_set!
@@ -25,13 +33,13 @@ module Simplec
25
33
  end
26
34
 
27
35
  def validate_slug!
28
- return if self.slug.nil?
36
+ return if self.slug.blank?
29
37
  similar = self.class.where(slug: self.slug).where.not(id: self.id)
30
38
  return if similar.size == 0
31
39
  return if (
32
40
  similar.map(&:subdomain_ids).flatten & self.subdomain_ids
33
41
  ).length == 0
34
- errors.add :slug, 'slug must be unique across linked subdomains'
42
+ errors.add :slug, 'must be unique across linked subdomains'
35
43
  end
36
44
 
37
45
  end
@@ -9,6 +9,14 @@ module Simplec
9
9
  validate :validate_subdomain!
10
10
  validate :validate_slug!
11
11
 
12
+ # @!visibility private
13
+ module Normalizers
14
+ def slug=(val)
15
+ super val.blank? ? nil : val
16
+ end
17
+ end
18
+ prepend Normalizers
19
+
12
20
  private
13
21
 
14
22
  def validate_subdomain!
@@ -17,12 +25,13 @@ module Simplec
17
25
  end
18
26
 
19
27
  def validate_slug!
28
+ return if self.slug.blank?
20
29
  similar = self.class.where(slug: self.slug).where.not(id: self.id)
21
30
  return if similar.size == 0
22
31
  return if (
23
32
  similar.map(&:subdomain_ids).flatten & self.subdomain_ids
24
33
  ).length == 0
25
- errors.add :slug, 'slug must be unique across linked subdomains'
34
+ errors.add :slug, 'must be unique across linked subdomains'
26
35
  end
27
36
 
28
37
  end
@@ -392,13 +392,12 @@ module Simplec
392
392
  # @!visibility private
393
393
  module Normalizers
394
394
  def slug=(val)
395
- val = val ? val.to_s.split('/').reject(&:blank?).join('/') : val
396
- super val
395
+ super clean_path(val)
397
396
  end
398
397
 
399
398
  def slug
400
399
  if self.parent_id && self.parent.nil?
401
- self.path.to_s.split('/').reject(&:blank?).join('/')
400
+ clean_path(self.path)
402
401
  else
403
402
  super
404
403
  end
@@ -410,6 +409,12 @@ module Simplec
410
409
 
411
410
  private
412
411
 
412
+ def clean_path(val)
413
+ val ?
414
+ val.to_s.strip.gsub(/[\s-]+/, '-').gsub(/[^\w-]/, '').split('/').reject(&:blank?).join('/') :
415
+ val
416
+ end
417
+
413
418
  def validate_path_not_nil!
414
419
  return unless self.path.nil?
415
420
  errors.add :path, "cannot be nil"
@@ -1,3 +1,3 @@
1
1
  module Simplec
2
- VERSION = '0.8.0'
2
+ VERSION = '0.8.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails