agnostic_slugs 0.0.3 → 0.1.0

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: fa10cf987c7480af0bd58640ea23c4ec2d0bcafd
4
- data.tar.gz: 37d67d2dc2f2ebad912e4dfe7cc773f9c5c3b569
3
+ metadata.gz: a1a58e6b7b684d390a15b4d976983226571bdc15
4
+ data.tar.gz: 86d16686360559a0e5bf9d4be750925ee7d48e9a
5
5
  SHA512:
6
- metadata.gz: 574973a8d53a4a43c79a241de481073f67ac239c1e1e2db6f8e8e945e42df192ec11a3a34bfcb111576d984efe3548e5727a43e8948bd0257b5b27322fc7974e
7
- data.tar.gz: e9d047f189d87ea4556f26dcbbfb76cc48f2723930ae6bc8c5c613066024916c5e0e48d68fdafd9581a68b1feaf3864856c5ef39c33bde9187c7c9226997c345
6
+ metadata.gz: 78ffb9bce0bde0e5483894b0fffc5ea64003c5166d11e2f3351a3e3d0c757577924cdae97e88fd383e32644849647cfc5b4fc3ddba2dcc38ee5c1d5b61b66c15
7
+ data.tar.gz: 3257ed2b7a37e6952528efe15ab946fa8f2cce4418a5b07404ebaf79710ec2762c723eed72e66c611641c146165ade2f677033b1fbe941b91eb2b24f21f0ae61
@@ -1,6 +1,10 @@
1
+ # 0.1.0
2
+
3
+ * Can step through slugs with #step and .step
4
+
1
5
  # 0.0.3
2
6
 
3
- Handle Danish chars better
7
+ * Handle Danish chars better
4
8
 
5
9
  # 0.0.2
6
10
 
data/README.md CHANGED
@@ -23,6 +23,16 @@ slug.to_s # => "look-at-my-pretty-new-shoes"
23
23
  slug.next.to_s # => "look-at-my-pretty-new-shoes-2"
24
24
  ```
25
25
 
26
+ Or step through slugs to find a unique slug using your own business logic:
27
+
28
+ ```ruby
29
+ Slug.step('Hello world') do |slug|
30
+ my_repo.slug_unique?(slug)
31
+ end
32
+ # => "hello-world-7"
33
+ ```
34
+
35
+
26
36
  ## Contributing
27
37
 
28
38
  1. Fork it ( https://github.com/lasseebert/agnostic_slugs/fork )
@@ -2,6 +2,10 @@ module AgnosticSlugs
2
2
  class Slug
3
3
  attr_reader :original, :counter
4
4
 
5
+ def self.step(name, &block)
6
+ new(name).step(&block)
7
+ end
8
+
5
9
  def initialize(original, counter = 1)
6
10
  @original = original
7
11
  @counter = counter
@@ -11,6 +15,15 @@ module AgnosticSlugs
11
15
  self.class.new(original, counter + 1)
12
16
  end
13
17
 
18
+ def step
19
+ instance = self
20
+ loop do
21
+ break if yield(instance.to_s)
22
+ instance = instance.next
23
+ end
24
+ instance.to_s
25
+ end
26
+
14
27
  def to_s
15
28
  @slug ||= generate
16
29
  end
@@ -1,3 +1,3 @@
1
1
  module AgnosticSlugs
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -52,5 +52,14 @@ module AgnosticSlugs
52
52
  expect(slug.counter).to eq(1)
53
53
  end
54
54
  end
55
+
56
+ describe '.step' do
57
+ it 'returns the slug that was yielded true' do
58
+ result = Slug.step('Foo Bar') do |slug|
59
+ slug =~ /-7$/
60
+ end
61
+ expect(result).to eq('foo-bar-7')
62
+ end
63
+ end
55
64
  end
56
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agnostic_slugs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Skindstad Ebert