gastropod 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1bab165dd595a5aa7fe3a519b8e5e3d2a698f53
4
+ data.tar.gz: 2843c32e7bd53ed66603c5d163d45542b5e20527
5
+ SHA512:
6
+ metadata.gz: 62593b20515c4f196f1ad191df8f0349a8db6e47b1232246fb3876399bb474ddd2fa3880300bad9d90b505d7697ec9ce7c2b4d88a8ab7077ce024b846f54d8c1
7
+ data.tar.gz: 28e687e91c57af0916d5ca2a81f11284106f898aca1e569b1008bffcfae11236af4a55fdd5221d94a76893c20b7c6d56b25710b29b089b4a1fed381374482cc9
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # gastropod
2
2
 
3
- Simple library for generating slugs
3
+ [![Code Climate](https://codeclimate.com/github/vigetlabs/gastropod.png)](https://codeclimate.com/github/vigetlabs/gastropod)
4
4
 
5
- ![Code Climate](https://codeclimate.com/github/vigetlabs/gastropod.png)
5
+ Simple library for generating slugs
6
6
 
7
7
  ![gastropod](http://i.imgur.com/5UhkBfI.jpg)
8
8
 
@@ -35,7 +35,13 @@ module Gastropod
35
35
  end
36
36
 
37
37
  def slug_from_source
38
- slug_source.to_s.downcase.gsub(/[^a-zA-Z0-9\-_]+/, '-')
38
+ slug_source
39
+ .to_s
40
+ .strip
41
+ .downcase
42
+ .gsub(/[^a-zA-Z0-9\-_]+/, '-') # convert special chars to dashes
43
+ .gsub(/^\-+|\-+$/, '') # strip leading & trailing dashes
44
+ .squeeze('-') # squeeze multiple inline dashes
39
45
  end
40
46
 
41
47
  def generate_slug?
@@ -3,7 +3,7 @@ module Gastropod
3
3
  module Validations
4
4
  def self.included(base)
5
5
  base.validates :slug, :uniqueness => true
6
- base.validates :slug, :format => { :with => /^[a-z0-9-]+$/, :allow_blank => true }
6
+ base.validates :slug, :format => { :with => /\A[a-z0-9-]+\z/, :allow_blank => true }
7
7
  base.validates :slug, :presence => true
8
8
 
9
9
  base.before_validation :assign_generated_slug, :if => :generate_slug?
@@ -1,3 +1,3 @@
1
1
  module Gastropod
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -16,4 +16,20 @@ describe Gastropod do
16
16
 
17
17
  product2.slug.should == "jimmy-boy-2"
18
18
  end
19
+
20
+ it "does not start with or end with dashes" do
21
+ product1 = Product.create!(:name => "?knowm sayng?")
22
+ product2 = Product.create!(:name => " seem sayng ")
23
+
24
+ product1.slug.should == "knowm-sayng"
25
+ product2.slug.should == "seem-sayng"
26
+ end
27
+
28
+ it "does not include multiple dashes" do
29
+ product1 = Product.create!(:name => " hi- there")
30
+ product2 = Product.create!(:name => "foo-?")
31
+
32
+ product1.slug.should == "hi-there"
33
+ product2.slug.should == "foo"
34
+ end
19
35
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gastropod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - James Cook
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-27 00:00:00.000000000 Z
12
+ date: 2014-01-22 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
@@ -31,33 +28,29 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: sqlite3
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rspec
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  description: Simple library for generating slugs
@@ -73,40 +66,33 @@ files:
73
66
  - MIT-LICENSE
74
67
  - README.md
75
68
  - gastropod.gemspec
76
- - spec/db/activerecord.db
77
- - spec/db/fixtures.sqlite3
78
- - spec/db/sequel.db
79
69
  - spec/fixtures/product.rb
80
70
  - spec/lib/gastropod_spec.rb
81
71
  - spec/spec_helper.rb
82
72
  homepage: https://github.com/vigetlabs/gastropod
83
73
  licenses: []
74
+ metadata: {}
84
75
  post_install_message:
85
76
  rdoc_options: []
86
77
  require_paths:
87
78
  - lib
88
79
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
80
  requirements:
91
- - - ! '>='
81
+ - - '>='
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
85
  requirements:
97
- - - ! '>='
86
+ - - '>='
98
87
  - !ruby/object:Gem::Version
99
88
  version: '0'
100
89
  requirements: []
101
90
  rubyforge_project:
102
- rubygems_version: 1.8.23
91
+ rubygems_version: 2.0.3
103
92
  signing_key:
104
- specification_version: 3
93
+ specification_version: 4
105
94
  summary: Simple library for generating slugs
106
95
  test_files:
107
- - spec/db/activerecord.db
108
- - spec/db/fixtures.sqlite3
109
- - spec/db/sequel.db
110
96
  - spec/fixtures/product.rb
111
97
  - spec/lib/gastropod_spec.rb
112
98
  - spec/spec_helper.rb
Binary file
Binary file
Binary file