slugtastic 1.2.1 → 1.3.1

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: 704240d3d16bf9fe3471f748b594694e451ad2fd
4
- data.tar.gz: 158d286f398fcfa33234fc99356b8e4728816a0c
3
+ metadata.gz: fedfdd70757c326282c3afa06061ff5219db0ad2
4
+ data.tar.gz: c6c87146a76046a04381be4c0b4552262a131065
5
5
  SHA512:
6
- metadata.gz: 93063ba1a143540d6ce7db8552c4e29031475dd0be8bac1833dcf3a0644a30404e9f27f16969d35a561806d1edb86e7bd7f6ea5abd1c14513c40d2c01b10a660
7
- data.tar.gz: cfaf954291e13b2d8e9cc9a0cc080711189cc8dcaa23aa4f8a77ff7a3b1c54b5893ca365818427073bc3aad8163bf98c77991010530ff7780da108a3cfef5892
6
+ metadata.gz: e6817d70b75343f27d0cb41ec3c1b795b07deb31c5b3446ac2971aceb7533e808b17d9f98ffa5a1670f9619b8646ac568f7b94dfb6474eca820d1f7b88acd449
7
+ data.tar.gz: c6e05d16648c4b4bd631cc560541ab7eb100c0888d8617fcc6435a651c808b75aa5c0d191e59fd5c793eeb40dabbe8dacce508b6362afcdf0ae527aeb05b4cc1
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ AllCops:
8
+ Include:
9
+ - '**/Rakefile'
10
+ - '**/config.ru'
11
+ Exclude:
12
+ - 'db/**/*'
13
+ - 'config/**/*'
14
+ - 'script/**/*'
15
+ - 'bin/**/*'
16
+ - !ruby/regexp /old_and_unused\.rb$/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slugtastic (1.2.1)
4
+ slugtastic (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,17 +12,22 @@ GEM
12
12
  i18n (~> 0.5.0)
13
13
  activesupport (3.0.20)
14
14
  builder (2.1.2)
15
- diff-lcs (1.1.3)
16
- i18n (0.5.0)
17
- rake (10.0.3)
18
- rspec (2.12.0)
19
- rspec-core (~> 2.12.0)
20
- rspec-expectations (~> 2.12.0)
21
- rspec-mocks (~> 2.12.0)
22
- rspec-core (2.12.2)
23
- rspec-expectations (2.12.1)
24
- diff-lcs (~> 1.1.3)
25
- rspec-mocks (2.12.2)
15
+ diff-lcs (1.2.5)
16
+ i18n (0.5.4)
17
+ rake (11.1.1)
18
+ rspec (3.4.0)
19
+ rspec-core (~> 3.4.0)
20
+ rspec-expectations (~> 3.4.0)
21
+ rspec-mocks (~> 3.4.0)
22
+ rspec-core (3.4.4)
23
+ rspec-support (~> 3.4.0)
24
+ rspec-expectations (3.4.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.4.0)
27
+ rspec-mocks (3.4.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.4.0)
30
+ rspec-support (3.4.1)
26
31
  supermodel (0.1.6)
27
32
  activemodel (~> 3.0.0)
28
33
 
@@ -30,7 +35,10 @@ PLATFORMS
30
35
  ruby
31
36
 
32
37
  DEPENDENCIES
33
- rake
34
- rspec
38
+ rake (~> 11.1)
39
+ rspec (~> 3.4)
35
40
  slugtastic!
36
- supermodel
41
+ supermodel (~> 0)
42
+
43
+ BUNDLED WITH
44
+ 1.11.2
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Dan Barber
1
+ Copyright (c) 2015 Dan Barber
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
- # Slugtastic [![Build Status](https://secure.travis-ci.org/danbee/slugtastic.png?branch=master)](http://travis-ci.org/danbee/slugtastic)
1
+ # Slugtastic
2
2
 
3
- Simple gem for autogenerating permalink style slugs for your ActiveRecord models.
3
+ [![Codeship Status for danbee/slugtastic](https://codeship.com/projects/7a08ef30-0518-0132-d4b6-223503fac7d3/status?branch=master)](https://codeship.com/projects/30797)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/slugtastic.svg)](https://badge.fury.io/rb/slugtastic)
6
+
7
+ Simple gem for autogenerating permalink style slugs for your ActiveRecord
8
+ models.
4
9
 
5
10
  ## Requirements
6
11
 
7
- * Ruby 1.9.2 or 1.9.3
12
+ * Ruby 2.0.0+
8
13
  * Rails 3.1 or higher.
9
14
 
10
- It should work with Rails 3.0 but it hasn't been tested.
11
-
12
15
  ## Installation
13
16
 
14
17
  Add this line to your application's Gemfile:
@@ -27,9 +30,11 @@ Or install it yourself as:
27
30
 
28
31
  Usage is very simple. Just add the following to your model:
29
32
 
30
- has_slug :slug, :from => :title
33
+ slug :slug, from: :title
31
34
 
32
- This will generate a slug string from the title atrribute and store it in the slug attribute unless the slug already contains a string. The slug is generated pre-validation so you can still use `validates_presence_of :slug`.
35
+ This will generate a slug string from the title attribute and store it in the
36
+ slug attribute unless the slug already contains a string. The slug is generated
37
+ pre-validation so you can still use `validates_presence_of :slug`.
33
38
 
34
39
  There are no extra options at present.
35
40
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
- require "rspec/core/rake_task"
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
@@ -1,6 +1,5 @@
1
1
  module Slugtastic
2
2
  module ModelAdditions
3
-
4
3
  # To generate a slug from another value, call <tt>has_slug</tt> in any
5
4
  # ActiveRecord model and pass in the name of the slug attribute.
6
5
  # By default the slug will be generated from the <tt>title</tt> attribute, but
@@ -9,12 +8,20 @@ module Slugtastic
9
8
  # class Article < ActiveRecord::Base
10
9
  # has_slug :slug, :from => :title
11
10
  # end
12
- def has_slug name, options = {}
13
- options.reverse_merge!({ :from => :title })
14
- before_validation do |record|
15
- send("#{name}=", Slugtastic.generate_slug(send(options[:from]), options[:delimiter])) if send(name).nil? or send(name).blank?
11
+ #
12
+ def slug(name, options = {})
13
+ options.reverse_merge!(from: :title)
14
+ before_validation do
15
+ if send(name).nil? || send(name).blank?
16
+ send("#{name}=", Slugtastic.generate_slug(send(options[:from]), options[:delimiter]))
17
+ end
16
18
  end
17
19
  end
18
20
 
21
+ def has_slug(name, options = {})
22
+ $stderr.puts '[deprecated] Slugtastic: `has_slug` has been renamed `slug` and will likely '\
23
+ 'be removed in a future version.'
24
+ slug(name, options)
25
+ end
19
26
  end
20
27
  end
@@ -1,6 +1,6 @@
1
1
  module Slugtastic
2
2
  class Railtie < Rails::Railtie
3
- initializer "slugtastic.model_additions" do
3
+ initializer 'slugtastic.model_additions' do
4
4
  ActiveSupport.on_load :active_record do
5
5
  extend ModelAdditions
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module Slugtastic
2
- VERSION = "1.2.1"
2
+ VERSION = '1.3.1'.freeze
3
3
  end
data/lib/slugtastic.rb CHANGED
@@ -1,14 +1,12 @@
1
- require "slugtastic/version"
2
- require "slugtastic/model_additions"
3
- require "slugtastic/railtie" if defined? Rails
1
+ require 'slugtastic/version'
2
+ require 'slugtastic/model_additions'
3
+ require 'slugtastic/railtie' if defined? Rails
4
4
 
5
5
  module Slugtastic
6
6
  def self.generate_slug(string, delimiter = nil)
7
7
  return if string.nil?
8
8
  slug = string.parameterize
9
- if delimiter
10
- slug.gsub!("-", delimiter)
11
- end
9
+ slug.gsub!('-', delimiter) if delimiter
12
10
  slug
13
11
  end
14
12
  end
data/slugtastic.gemspec CHANGED
@@ -4,9 +4,10 @@ require File.expand_path('../lib/slugtastic/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Dan Barber"]
6
6
  gem.email = ["danbee@gmail.com"]
7
+ gem.licenses = ['MIT']
7
8
  gem.description = %q{A simple slug string generator for ActiveRecord. Will populate a slug attribute from another attribute.}
8
9
  gem.summary = %q{A simple slug string generator for ActiveRecord.}
9
- gem.homepage = ""
10
+ gem.homepage = "http://danbarber.me/slugtastic"
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,7 +16,7 @@ Gem::Specification.new do |gem|
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = Slugtastic::VERSION
17
18
 
18
- gem.add_development_dependency "rake"
19
- gem.add_development_dependency "rspec"
20
- gem.add_development_dependency "supermodel"
19
+ gem.add_development_dependency "rake", "~> 11.1"
20
+ gem.add_development_dependency "rspec", "~> 3.4"
21
+ gem.add_development_dependency "supermodel", "~> 0"
21
22
  end
@@ -8,38 +8,47 @@ end
8
8
 
9
9
  class Model < BaseModel
10
10
  attr_accessor :slug, :name
11
- has_slug :slug, from: :name
11
+ slug :slug, from: :name
12
12
  end
13
13
 
14
14
  class ModelDefault < BaseModel
15
15
  attr_accessor :slug, :title
16
- has_slug :slug
16
+ slug :slug
17
17
  end
18
18
 
19
19
  class ModelDelimiter < BaseModel
20
20
  attr_accessor :slug, :title
21
- has_slug :slug, delimiter: "_"
21
+ slug :slug, delimiter: '_'
22
+ end
23
+
24
+ class ModelAlias < BaseModel
25
+ attr_accessor :slug, :title
26
+ has_slug :slug
22
27
  end
23
28
 
24
29
  describe Slugtastic::ModelAdditions do
25
- it "generates a slug from the name" do
26
- Model.create!(:name => "A Simple Name").slug.should eq "a-simple-name"
30
+ it 'generates a slug from the name' do
31
+ expect(Model.create!(name: 'A Simple Name').slug).to eq 'a-simple-name'
27
32
  end
28
33
 
29
- it "defaults to generating the slug from title" do
30
- ModelDefault.create!(:title => "A Simple Title").slug.should eq "a-simple-title"
34
+ it 'defaults to generating the slug from title' do
35
+ expect(ModelDefault.create!(title: 'A Simple Title').slug).to eq 'a-simple-title'
31
36
  end
32
37
 
33
- it "generates a slug from the title with delimiter substitutions" do
34
- ModelDelimiter.create!(:title => "A Simple Title").slug.should eq "a_simple_title"
38
+ it 'generates a slug from the title with delimiter substitutions' do
39
+ expect(ModelDelimiter.create!(title: 'A Simple Title').slug).to eq 'a_simple_title'
35
40
  end
36
41
 
37
42
  it "doesn't regenerate the slug if it already exists" do
38
- model = Model.create!(:name => "A Simple Name")
39
- model.slug.should eq "a-simple-name"
43
+ model = Model.create!(name: 'A Simple Name')
44
+ expect(model.slug).to eq 'a-simple-name'
40
45
 
41
- model.title = "A new title"
46
+ model.title = 'A new title'
42
47
  model.save
43
- model.slug.should eq "a-simple-name"
48
+ expect(model.slug).to eq 'a-simple-name'
49
+ end
50
+
51
+ it 'aliases slug to has_slug for backwards compatibility' do
52
+ expect(ModelAlias.create!(title: 'A Simple Title').slug).to eq 'a-simple-title'
44
53
  end
45
54
  end
@@ -2,34 +2,34 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Slugtastic do
5
- describe ".generate_slug" do
6
- it "returns empty if the input string is empty" do
7
- Slugtastic.generate_slug("").should eq ""
5
+ describe '.generate_slug' do
6
+ it 'returns empty if the input string is empty' do
7
+ expect(Slugtastic.generate_slug('')).to eq ''
8
8
  end
9
9
 
10
- it "generates a slug from a simple string" do
11
- Slugtastic.generate_slug("A simple string.").should eq "a-simple-string"
10
+ it 'generates a slug from a simple string' do
11
+ expect(Slugtastic.generate_slug('A simple string.')).to eq 'a-simple-string'
12
12
  end
13
13
 
14
- it "substitutes hyphens for delimiter if specified" do
15
- Slugtastic.generate_slug("A simple string.", "_").should eq "a_simple_string"
14
+ it 'substitutes hyphens for delimiter if specified' do
15
+ expect(Slugtastic.generate_slug('A simple string.', '_')).to eq 'a_simple_string'
16
16
  end
17
17
 
18
- it "generates a slug from a string with numbers" do
19
- Slugtastic.generate_slug("Slugtastic was built in 2012.").should eq "slugtastic-was-built-in-2012"
18
+ it 'generates a slug from a string with numbers' do
19
+ expect(Slugtastic.generate_slug('Slugtastic was built in 2012.')).to eq 'slugtastic-was-built-in-2012'
20
20
  end
21
21
 
22
- it "handles strings with hypens in them" do
23
- Slugtastic.generate_slug("A string - with Hyphens").should eq "a-string-with-hyphens"
22
+ it 'handles strings with hypens in them' do
23
+ expect(Slugtastic.generate_slug('A string - with Hyphens')).to eq 'a-string-with-hyphens'
24
24
  end
25
25
 
26
- it "handles strings with other characters in them" do
27
- Slugtastic.generate_slug("A string, with /All sorts!").should eq "a-string-with-all-sorts"
26
+ it 'handles strings with other characters in them' do
27
+ expect(Slugtastic.generate_slug('A string, with /All sorts!')).to eq 'a-string-with-all-sorts'
28
28
  end
29
29
 
30
- it "handles basic transliteration" do
31
- Slugtastic.generate_slug("Un été À la maison.").should eq "un-ete-a-la-maison"
32
- Slugtastic.generate_slug("Ātri brūna lapsa").should eq "atri-bruna-lapsa"
30
+ it 'handles basic transliteration' do
31
+ expect(Slugtastic.generate_slug('Un été À la maison.')).to eq 'un-ete-a-la-maison'
32
+ expect(Slugtastic.generate_slug('Ātri brūna lapsa')).to eq 'atri-bruna-lapsa'
33
33
  end
34
34
  end
35
35
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,2 @@
1
- require "slugtastic"
2
- require "supermodel"
1
+ require 'slugtastic'
2
+ require 'supermodel'
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slugtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Barber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-15 00:00:00.000000000 Z
11
+ date: 2016-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '11.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '11.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: supermodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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
54
  version: '0'
55
55
  description: A simple slug string generator for ActiveRecord. Will populate a slug
@@ -60,9 +60,10 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .rspec
65
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".travis.yml"
66
67
  - CHANGELOG.md
67
68
  - Gemfile
68
69
  - Gemfile.lock
@@ -77,8 +78,9 @@ files:
77
78
  - spec/slugtastic/model_additions_spec.rb
78
79
  - spec/slugtastic_spec.rb
79
80
  - spec/spec_helper.rb
80
- homepage: ''
81
- licenses: []
81
+ homepage: http://danbarber.me/slugtastic
82
+ licenses:
83
+ - MIT
82
84
  metadata: {}
83
85
  post_install_message:
84
86
  rdoc_options: []
@@ -86,17 +88,17 @@ require_paths:
86
88
  - lib
87
89
  required_ruby_version: !ruby/object:Gem::Requirement
88
90
  requirements:
89
- - - '>='
91
+ - - ">="
90
92
  - !ruby/object:Gem::Version
91
93
  version: '0'
92
94
  required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  requirements:
94
- - - '>='
96
+ - - ">="
95
97
  - !ruby/object:Gem::Version
96
98
  version: '0'
97
99
  requirements: []
98
100
  rubyforge_project:
99
- rubygems_version: 2.0.0
101
+ rubygems_version: 2.5.1
100
102
  signing_key:
101
103
  specification_version: 4
102
104
  summary: A simple slug string generator for ActiveRecord.