mongoid-permalinks 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ # Because this is a gem, ignore Gemfile.lock:
2
+
3
+ Gemfile.lock
4
+
5
+ # And because this is Ruby, ignore the following
6
+ # (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore):
7
+
8
+ *.gem
9
+ *.rbc
10
+ .bundle
11
+ .config
12
+ coverage
13
+ InstalledFiles
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+
22
+ # YARD artifacts
23
+ .yardoc
24
+ _yardoc
25
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'minitest'
6
+ gem 'rake'
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # mongoid-permalinks
2
+
3
+ Mongoid::Permalinks adds a permalink based on your document `to_s` method.
4
+
5
+ ## Installation
6
+
7
+ In your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mongoid-permalinks'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ class Document
17
+ include Mongoid::Document
18
+ include Mongoid::Permalinks
19
+
20
+ field :name, type: String
21
+
22
+ alias_method :to_s, :name
23
+ end
24
+ ```
25
+
26
+ ```ruby
27
+ document = Document.create(name: 'Mongoid::Permalinks is awesome')
28
+ document.permalink # => 'mongoid-permalinks-is-awesome'
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
38
+
39
+ ## Copyright
40
+
41
+ (The MIT license)
42
+
43
+ Copyright (c) 2012 Mario Uher
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining
46
+ a copy of this software and associated documentation files (the
47
+ "Software"), to deal in the Software without restriction, including
48
+ without limitation the rights to use, copy, modify, merge, publish,
49
+ distribute, sublicense, and/or sell copies of the Software, and to
50
+ permit persons to whom the Software is furnished to do so, subject to
51
+ the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be
54
+ included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
57
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
59
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
60
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
61
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
62
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = Dir.glob('spec/**/*_spec.rb')
6
+ end
7
+
8
+ task(default: :test)
@@ -0,0 +1,5 @@
1
+ module Mongoid
2
+ module Permalinks
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'active_support'
2
+ require 'mongoid'
3
+
4
+ module Mongoid
5
+ module Permalinks
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ field :permalink, type: String
10
+
11
+ before_save :set_permalink
12
+ end
13
+
14
+ private
15
+ def set_permalink
16
+ self.permalink = (permalink.presence || to_s).parameterize
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require './lib/mongoid/permalinks/version'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'mongoid-permalinks'
5
+ gem.version = Mongoid::Permalinks::VERSION
6
+ gem.authors = 'Mario Uher'
7
+ gem.email = 'uher.mario@gmail.com'
8
+ gem.homepage = 'https://github.com/haihappen/mongoid-permalinks'
9
+ gem.summary = 'Permalinks for your Mongoid documents.'
10
+ gem.description = 'Mongoid::Permalink adds a permalink based on your document to_s method.'
11
+
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.require_path = 'lib'
14
+
15
+ gem.add_dependency 'activesupport'
16
+ gem.add_dependency 'mongoid'
17
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Mongoid::Permalinks do
4
+ it 'adds permalink field' do
5
+ Document.fields['permalink'].type.must_equal String
6
+ end
7
+
8
+
9
+ describe 'setting permalink' do
10
+ subject { Document.create(permalink: permalink, name: 'Name') }
11
+ let(:value) { subject.permalink }
12
+
13
+
14
+ describe 'providing an empty permalink' do
15
+ let(:permalink) { '' }
16
+
17
+
18
+ it 'parameterizes name instead' do
19
+ value.must_equal 'name'
20
+ end
21
+ end
22
+
23
+
24
+ describe 'providing an permalink' do
25
+ let(:permalink) { 'custom permalink' }
26
+
27
+
28
+ it 'parameterizes it' do
29
+ value.must_equal 'custom-permalink'
30
+ end
31
+ end
32
+
33
+
34
+ describe 'providing an permalink with trailing spaces' do
35
+ let(:permalink) { ' custom permalink ' }
36
+
37
+
38
+ it 'parameterizes it and removes the spaces' do
39
+ value.must_equal 'custom-permalink'
40
+ end
41
+ end
42
+
43
+
44
+ describe 'providing an permalink with special characters' do
45
+ let(:permalink) { 'Donald E. Knuth' }
46
+
47
+
48
+ it 'parameterizes it and makes it pretty' do
49
+ value.must_equal 'donald-e-knuth'
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ describe 'having localized permalink fields' do
56
+ subject { Localized.new }
57
+
58
+
59
+ it 'works too' do
60
+ { en: 'English', de: 'Deutsch' }.each do |locale, permalink|
61
+ I18n.locale = locale
62
+ subject.permalink = permalink
63
+ subject.save
64
+
65
+ subject.permalink.must_equal permalink.parameterize
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'minitest/spec'
4
+
5
+ require './lib/mongoid/permalinks'
6
+
7
+ # Load support *.rb files in ./support
8
+ Dir[File.expand_path('../support/*.rb', __FILE__)].each { |file| require file }
@@ -0,0 +1 @@
1
+ Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), 'test')
@@ -0,0 +1,18 @@
1
+ class Document
2
+ include Mongoid::Document
3
+ include Mongoid::Permalinks
4
+
5
+ field :name, type: String
6
+
7
+ alias_method :to_s, :name
8
+ end
9
+
10
+ class Localized
11
+ include Mongoid::Document
12
+ include Mongoid::Permalinks
13
+
14
+ field :name, type: String, localize: true
15
+ field :permalink, type: String, localize: true
16
+
17
+ alias_method :to_s, :name
18
+ end
@@ -0,0 +1,8 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: mongoid_permalinks_test
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ consistency: :strong
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-permalinks
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.0
6
+ platform: ruby
7
+ authors:
8
+ - Mario Uher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ none: false
21
+ name: activesupport
22
+ type: :runtime
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ name: mongoid
38
+ type: :runtime
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ description: Mongoid::Permalink adds a permalink based on your document to_s method.
47
+ email: uher.mario@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - Gemfile
54
+ - README.md
55
+ - Rakefile
56
+ - lib/mongoid/permalinks.rb
57
+ - lib/mongoid/permalinks/version.rb
58
+ - mongoid-permalinks.gemspec
59
+ - spec/permalinks_spec.rb
60
+ - spec/spec_helper.rb
61
+ - spec/support/connection.rb
62
+ - spec/support/document.rb
63
+ - spec/support/mongoid.yml
64
+ homepage: https://github.com/haihappen/mongoid-permalinks
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ none: false
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ none: false
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Permalinks for your Mongoid documents.
88
+ test_files: []