slugworth 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -5
- data/lib/slugworth.rb +12 -7
- data/lib/slugworth/version.rb +1 -1
- data/lib/slugworth_shared_examples.rb +7 -1
- data/slugworth.gemspec +6 -6
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c5a2617fdb5cb5bfebeb4545eeb25e19833dba
|
4
|
+
data.tar.gz: 4667dd9a4eab4e2934a22694fe730bb239da6f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2695d24b686191d58b56ffd5e04e2083b5cc059be663fc6a5a433a096de361a9a060b339f8f67471dcae66439bc5004026a02b69ad502a9cfed69544f0c34473
|
7
|
+
data.tar.gz: 112887759a1197cbc69e74e06597cb5ae5f062a4143b31a09c31ac9883f2334d2610d22ae4553201c9eed94928e66459f7aefb27a26a96a68eafe32a106ba97b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
![Slugworth](http://f.cl.ly/items/3T1K3g040S0u2l0G0d3V/slugworth_header.png)
|
2
2
|
|
3
|
-
[![Gem Version](
|
4
|
-
[![Build Status](
|
5
|
-
[![Code Climate](
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/slugworth.svg?style=flat)](http://badge.fury.io/rb/slugworth)
|
4
|
+
[![Build Status](http://img.shields.io/travis/mattpolito/slugworth/master.svg?style=flat)](https://travis-ci.org/mattpolito/slugworth)
|
5
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/mattpolito/slugworth.svg?style=flat)](https://codeclimate.com/github/mattpolito/slugworth)
|
6
6
|
|
7
7
|
Simple slug functionality for your ActiveRecord objects
|
8
8
|
|
@@ -41,12 +41,12 @@ class User < ActiveRecord::Base
|
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
44
|
-
After you `include` the `Slugworth` module, all you need to do is declare what method will be used to create the slug. The method passed to `slugged_with` will then be
|
44
|
+
After you `include` the `Slugworth` module, all you need to do is declare what method will be used to create the slug. The method passed to `slugged_with` will then be parameterized.
|
45
45
|
|
46
46
|
This provides most of the default slug functionality you would need.
|
47
47
|
|
48
48
|
* Finders `.find_by_slug` & `.find_by_slug!` are provided. This will, of course, do what you expect and find a single record by the slug attribute provided.
|
49
|
-
* `#to_param` has been defined as a
|
49
|
+
* `#to_param` has been defined as a parameterized version of the attribute declared to `slugged_with`.
|
50
50
|
* Validations stating that `slug` is present and unique in the database.
|
51
51
|
|
52
52
|
### Scoping uniqueness
|
data/lib/slugworth.rb
CHANGED
@@ -5,15 +5,15 @@ module Slugworth
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
cattr_accessor :slug_attribute, :slug_scope, :slug_incremental, :slug_updatable
|
8
|
-
before_validation(:add_slug)
|
8
|
+
before_validation(:add_slug, if: :slug_attribute_value)
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
def slugged_with(slug_attribute, opts={})
|
13
|
-
self.slug_attribute
|
14
|
-
self.slug_scope
|
12
|
+
def slugged_with(slug_attribute, opts = {})
|
13
|
+
self.slug_attribute = slug_attribute
|
14
|
+
self.slug_scope = opts.delete(:scope)
|
15
15
|
self.slug_incremental = opts.delete(:incremental)
|
16
|
-
self.slug_updatable
|
16
|
+
self.slug_updatable = opts.delete(:updatable)
|
17
17
|
validates_uniqueness_of :slug, scope: slug_scope
|
18
18
|
end
|
19
19
|
|
@@ -29,6 +29,7 @@ module Slugworth
|
|
29
29
|
def to_param; slug; end
|
30
30
|
|
31
31
|
private
|
32
|
+
|
32
33
|
def add_slug
|
33
34
|
self.slug = processed_slug if generate_slug?
|
34
35
|
end
|
@@ -37,12 +38,16 @@ module Slugworth
|
|
37
38
|
!slug.present? || slug_updatable && changes[slug_attribute].present?
|
38
39
|
end
|
39
40
|
|
41
|
+
def slug_attribute_value
|
42
|
+
public_send(slug_attribute)
|
43
|
+
end
|
44
|
+
|
40
45
|
def processed_slug
|
41
|
-
slug_incremental ?
|
46
|
+
slug_incremental ? process_incremental_slug : parameterized_slug
|
42
47
|
end
|
43
48
|
|
44
49
|
def parameterized_slug
|
45
|
-
|
50
|
+
slug_attribute_value.parameterize
|
46
51
|
end
|
47
52
|
|
48
53
|
def process_incremental_slug
|
data/lib/slugworth/version.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
shared_examples_for :has_slug_functionality do
|
2
2
|
describe "#slug" do
|
3
3
|
context "when no slug is set" do
|
4
|
-
specify 'slug is generated' do
|
4
|
+
specify 'slug is generated with slug attribute' do
|
5
5
|
obj = described_class.new(described_class.slug_attribute => 'Generated slug')
|
6
6
|
obj.valid?
|
7
7
|
expect(obj.slug).to eq('generated-slug')
|
8
8
|
end
|
9
|
+
|
10
|
+
specify 'slug is not generated with no slug attribute' do
|
11
|
+
obj = described_class.new
|
12
|
+
obj.valid?
|
13
|
+
expect(obj.slug).to be_nil
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
context "when the slug is set" do
|
data/slugworth.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "slugworth/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "slugworth"
|
@@ -17,13 +17,13 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version =
|
20
|
+
spec.required_ruby_version = ">= 1.9.2"
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "rspec", "~>
|
25
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
25
|
+
spec.add_development_dependency "activerecord", "~> 4.0.0"
|
26
26
|
spec.add_development_dependency "pry"
|
27
|
-
spec.add_development_dependency "database_cleaner",
|
27
|
+
spec.add_development_dependency "database_cleaner", "~> 1.0.1"
|
28
28
|
spec.add_development_dependency "sqlite3"
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugworth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Polito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activerecord
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.4.
|
150
|
+
rubygems_version: 2.4.6
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Easy slug functionality
|