mongoid-slugify 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee34888fc56b34db526225ea77a91d71ae56dd75
4
+ data.tar.gz: 80b4beff147eee4750ca115dc1fcde4c9b0bf26b
5
+ SHA512:
6
+ metadata.gz: 809636ab758c08cbbcc2594120b5d74cb0423f82017dd51efd5147c96252bc73960fd3f83f8551aa944704c15ec0b9fad1c76258a08735e3b7d5d63cb9a82651
7
+ data.tar.gz: bde6531b8cd3eb0fda3a17f0288cd80501eb2964dfd195d4252659e5213356fb3c81b2115e60b24103bb6387ca4b9c3838ea6cef17bbabd03416bb12844269e2
data/.gitignore CHANGED
@@ -3,7 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- /gemfiles
6
+ /gemfiles/*.gemfile.lock
7
7
  Gemfile.lock
8
8
  InstalledFiles
9
9
  _yardoc
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- install: 'bundle install && bundle exec rake appraisal:install'
2
+ services: mongodb
3
3
  gemfile:
4
4
  - gemfiles/mongoid2.gemfile
5
5
  - gemfiles/mongoid3.gemfile
@@ -8,7 +8,19 @@ rvm:
8
8
  - 1.9.2
9
9
  - 1.9.3
10
10
  - rbx-18mode
11
- #- rbx-19mode
11
+ - rbx-19mode
12
12
  - jruby-18mode
13
13
  - jruby-19mode
14
14
  - ree
15
+ matrix:
16
+ exclude:
17
+ - rvm: 1.8.7
18
+ gemfile: gemfiles/mongoid3.gemfile
19
+ - rvm: rbx-18mode
20
+ gemfile: gemfiles/mongoid3.gemfile
21
+ - rvm: jruby-18mode
22
+ gemfile: gemfiles/mongoid3.gemfile
23
+ - rvm: ree
24
+ gemfile: gemfiles/mongoid3.gemfile
25
+ - rvm: 1.9.2
26
+ gemfile: gemfiles/mongoid3.gemfile
data/Appraisals CHANGED
@@ -1,8 +1,12 @@
1
- appraise "mongoid2" do
1
+ appraise 'mongoid2' do
2
2
  gem 'mongoid', '~> 2.0'
3
3
  gem 'bson_ext', :platforms => :ruby
4
4
  end
5
5
 
6
- appraise "mongoid3" do
7
- gem 'mongoid', '~> 3.0.0.rc'
6
+ appraise 'mongoid3' do
7
+ gem 'mongoid', '~> 3.0'
8
+ end
9
+
10
+ appraise 'mongoid4' do
11
+ gem 'mongoid', '~> 4.0'
8
12
  end
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Mongoid::Slugify
2
+
3
+ Mongoid::Slugify is a gem, which helps you with generating slugs for your Mongoid models.
4
+
5
+ [![Travis CI](https://secure.travis-ci.org/fxposter/mongoid-slugify.png)](http://travis-ci.org/fxposter/mongoid-slugify)
6
+
7
+ ## Installation
8
+
9
+ Add Mongoid::Slugify to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mongoid-slugify'
13
+ ```
14
+
15
+ Since 0.1.0 Mongoid::Slugify supports both Mongoid 2.x, 3.x and 4.x releases.
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ class Product
21
+ include Mongoid::Document
22
+ include Mongoid::Slugify
23
+
24
+ field :title
25
+
26
+ private
27
+ def generate_slug
28
+ title.parameterize
29
+ end
30
+ end
31
+ ```
32
+
33
+ As you can see, you should make 2 things:
34
+
35
+ - include Mongoid::Slugify module to your model
36
+ - provide a way to generate initial slug for your model (based on any fields, that you want)
37
+
38
+ If do those - Mongoid::Slugify will save the generated slug to `slug` field of your model and will care about slug uniqueness (it will append "-1", "-2", etc to your slugs until it finds free one).
39
+
40
+ Mongooid::Slugify gives you these additional functions:
41
+
42
+ - redefines `to_param` method, so that it returns slug, if it's present, and model id otherwise
43
+ - `Model.(find_by_slug/find_by_slug!/find_by_slug_or_id/find_by_slug_or_id!)` methods.
44
+ If you don't want to generate slugs for all your existing objects (so that to_param will return model ids) - you should prefer the latter two in your controllers.
45
+
46
+ ## Warning
47
+
48
+ This library will not provide a way to generate initial slugs, at least in the nearest future. I just don't need it. If you need this functionality - please, contact me and we can discuss it. Or simply open pull request. :)
49
+
50
+ If you need all-out-of-the-box solution - look at [Mongoid Slug](https://github.com/digitalplaywright/mongoid-slug), it's far more full featured and actively developed.
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "mongoid", "~> 2.0"
6
+ gem "bson_ext", :platforms => :ruby
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "mongoid", "~> 3.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0"
6
+
7
+ gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Slugify
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -4,15 +4,15 @@ require 'active_support/concern'
4
4
 
5
5
  module Mongoid
6
6
  module Slugify
7
- def self.mongoid3?
8
- defined?(Mongoid::VERSION) && Gem::Version.new(Mongoid::VERSION) >= Gem::Version.new('3.0.0.rc')
7
+ def self.at_least_mongoid3?
8
+ defined?(Mongoid::VERSION) && Gem::Version.new(Mongoid::VERSION) >= Gem::Version.new('3.0.0')
9
9
  end
10
10
 
11
11
  extend ActiveSupport::Concern
12
12
 
13
13
  included do
14
14
  field :slug
15
- if Mongoid::Slugify.mongoid3?
15
+ if Mongoid::Slugify.at_least_mongoid3?
16
16
  index({ :slug => 1 }, { :unique => true })
17
17
  else
18
18
  index :slug, :unique => true
@@ -15,8 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Mongoid::Slugify::VERSION
17
17
 
18
- gem.add_runtime_dependency 'activesupport', '~> 3.0'
19
- gem.add_runtime_dependency 'mongoid', '>= 2.0', '< 4.0'
18
+ gem.add_runtime_dependency 'activesupport', '>= 3.0', '< 5.0'
19
+ gem.add_runtime_dependency 'mongoid', '>= 2.0', '< 5.0'
20
20
 
21
21
  gem.add_development_dependency 'rake'
22
22
  gem.add_development_dependency 'rspec'
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,22 @@
1
+ p ENV['BUNDLE_GEMFILE']
2
+
1
3
  require "bundler/setup"
2
4
  Bundler.require(:default, :development)
3
5
 
4
6
  Mongoid.configure do |config|
5
- if Mongoid::Slugify.mongoid3?
6
- config.sessions[:default] = { :database => 'mongoid_slugify_test', :hosts => ['localhost:27017'] }
7
+ if Mongoid::Slugify.at_least_mongoid3?
8
+ config.sessions[:default] = HashWithIndifferentAccess.new({ :database => 'mongoid_slugify_test', :hosts => ['localhost:27017'] })
7
9
  else
8
10
  config.master = Mongo::Connection.new.db('mongoid_slugify_test')
9
11
  end
10
12
  end
11
13
 
12
14
  DatabaseCleaner.strategy = :truncation
13
- DatabaseCleaner.orm = Mongoid::Slugify.mongoid3? ? :moped : :mongoid
15
+ DatabaseCleaner.orm = Mongoid::Slugify.at_least_mongoid3? ? :moped : :mongoid
14
16
 
15
17
  RSpec.configure do |config|
18
+ config.expect_with(:rspec) { |c| c.syntax = :should }
19
+
16
20
  config.before :each do
17
21
  DatabaseCleaner.start
18
22
  end
metadata CHANGED
@@ -1,170 +1,156 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongoid-slugify
3
- version: !ruby/object:Gem::Version
4
- hash: 1322991910812937300
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Pavel Forkert
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-06-12 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 2224468019386370560
29
- segments:
30
- - 3
31
- - 0
32
- version: "3.0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
33
23
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mongoid
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: mongoid
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
41
37
  - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 1017907466521848518
44
- segments:
45
- - 2
46
- - 0
47
- version: "2.0"
48
- - - <
49
- - !ruby/object:Gem::Version
50
- hash: 3455592072196224488
51
- segments:
52
- - 4
53
- - 0
54
- version: "4.0"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
55
43
  type: :runtime
56
- version_requirements: *id002
57
- - !ruby/object:Gem::Dependency
58
- name: rake
59
44
  prerelease: false
60
- requirement: &id003 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '2.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
63
57
  - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 2002549777813010636
66
- segments:
67
- - 0
68
- version: "0"
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
69
60
  type: :development
70
- version_requirements: *id003
71
- - !ruby/object:Gem::Dependency
72
- name: rspec
73
61
  prerelease: false
74
- requirement: &id004 !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
77
64
  - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 2002549777813010636
80
- segments:
81
- - 0
82
- version: "0"
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
83
74
  type: :development
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: database_cleaner
87
75
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
91
78
  - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 2002549777813010636
94
- segments:
95
- - 0
96
- version: "0"
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: database_cleaner
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
97
88
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: appraisal
101
89
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
105
92
  - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 2002549777813010636
108
- segments:
109
- - 0
110
- version: "0"
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: appraisal
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
111
102
  type: :development
112
- version_requirements: *id006
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
113
109
  description: Provides a simple way to add slug generation to a Mongoid model
114
- email:
110
+ email:
115
111
  - fxposter@gmail.com
116
112
  executables: []
117
-
118
113
  extensions: []
119
-
120
114
  extra_rdoc_files: []
121
-
122
- files:
123
- - .gitignore
124
- - .travis.yml
115
+ files:
116
+ - ".gitignore"
117
+ - ".travis.yml"
125
118
  - Appraisals
126
119
  - Gemfile
127
- - README.rdoc
120
+ - README.md
128
121
  - Rakefile
122
+ - gemfiles/mongoid2.gemfile
123
+ - gemfiles/mongoid3.gemfile
124
+ - gemfiles/mongoid4.gemfile
129
125
  - lib/mongoid-slugify.rb
130
126
  - lib/mongoid/slugify.rb
131
127
  - lib/mongoid/slugify/version.rb
132
128
  - mongoid-slugify.gemspec
133
129
  - spec/mongoid/slugify_spec.rb
134
130
  - spec/spec_helper.rb
135
- homepage: ""
131
+ homepage: ''
136
132
  licenses: []
137
-
133
+ metadata: {}
138
134
  post_install_message:
139
135
  rdoc_options: []
140
-
141
- require_paths:
136
+ require_paths:
142
137
  - lib
143
- required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
- requirements:
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
146
140
  - - ">="
147
- - !ruby/object:Gem::Version
148
- hash: 2002549777813010636
149
- segments:
150
- - 0
151
- version: "0"
152
- required_rubygems_version: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
155
145
  - - ">="
156
- - !ruby/object:Gem::Version
157
- hash: 2002549777813010636
158
- segments:
159
- - 0
160
- version: "0"
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
161
148
  requirements: []
162
-
163
149
  rubyforge_project:
164
- rubygems_version: 1.8.12
150
+ rubygems_version: 2.4.5
165
151
  signing_key:
166
- specification_version: 3
152
+ specification_version: 4
167
153
  summary: Managing slugs in Mongoid models
168
- test_files:
154
+ test_files:
169
155
  - spec/mongoid/slugify_spec.rb
170
156
  - spec/spec_helper.rb
data/README.rdoc DELETED
@@ -1,48 +0,0 @@
1
- = Mongoid::Slufigy
2
-
3
- Mongoid::Slufigy is a gem, which helps you with generating slugs for your Mongoid models.
4
-
5
- {<img src="https://secure.travis-ci.org/fxposter/mongoid-slugify.png" />}[http://travis-ci.org/fxposter/mongoid-slugify]
6
-
7
- == Installation
8
-
9
- Add Mongoid::Slufigy to your Gemfile:
10
-
11
- gem 'mongoid-slugify'
12
-
13
- Since 0.1.0 Mongoid::Slufigy supports both Mongoid 2.x and 3.x releases (since 3.0.0.rc).
14
-
15
- == Usage
16
-
17
- class Product
18
- include Mongoid::Document
19
- include Mongoid::Slugify
20
-
21
- field :title
22
-
23
- private
24
- def generate_slug
25
- title.parameterize
26
- end
27
- end
28
-
29
- As you can see, you should make 2 things:
30
-
31
- - include Mongoid::Slugify module to your model
32
- - provide a way to generate initial slug for your model (based on any fields, that you want)
33
-
34
- If do those - Mongooid::Slugify will save the generated slug to `slug` field of your model and will care about slug uniqueness
35
- (it will append "-1", "-2", etc to your slugs until it finds free one).
36
-
37
- Mongooid::Slugify gives you these additional functions:
38
-
39
- - redefines to_param method, so that it returns slug, if it's present, and model id otherwise
40
- - Model.(find_by_slug/find_by_slug!/find_by_slug_or_id/find_by_slug_or_id!) methods.
41
- If you don't want to generate slugs for all your existing objects (so that to_param will return model ids) - you should prefer the latter two in your controllers.
42
-
43
- == Warning
44
-
45
- This library will NEVER (at least not in the nearest future) provide a way to generate initial slugs. I just don't need it.
46
- Don't try to add this functionality to my library.
47
-
48
- If you need all-out-of-the-box solution - look at Mongoid Slug [https://github.com/hakanensari/mongoid-slug], it's far more full featured and actively developed.