mongoid-normalize-strings 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/mongoid-normalize-strings.rb +3 -0
- data/lib/mongoid-normalize-strings/normalize.rb +40 -0
- data/lib/mongoid-normalize-strings/version.rb +5 -0
- data/mongoid-normalize-strings.gemspec +26 -0
- data/spec/normalize_spec.rb +23 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/mongoid.yml +6 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 82cbebbb67d134e3c73f5031e15a3195a1e79f69
|
4
|
+
data.tar.gz: af32e857ea377f2af72317c0431a64e45b346505
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e82a88242a71987816ee2256414e12e7f8187a2b8c296f907433e3b6d15fcd586413a0e782c1dfa6d03becd7be74c93790376aacb3c548989ff3ed5ad7bc341c
|
7
|
+
data.tar.gz: 500beecd10065d3fbaff9fdde02c8265a1e7ec710e3360e2990b3a72981ca27b455a0b215fa53bfce38ac236e3462dec16e2ad588eafc6e1c34ccf11496e7908
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rafael Jurado
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Mongoid::Normalize::Strings
|
2
|
+
|
3
|
+
Normalize fields of type string in your Mongoid models.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mongoid-normalize-strings'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mongoid-normalize-strings
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class Person
|
23
|
+
include Mongoid::Document
|
24
|
+
include Mongoid::NormalizeStrings
|
25
|
+
|
26
|
+
field :name, type: String
|
27
|
+
normalize :name
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( http://github.com/<my-github-username>/mongoid-normalize-strings/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
##
|
2
|
+
# Let you add normalized fields to mongoid document.
|
3
|
+
# It saves normalized values of fields when save document.
|
4
|
+
#
|
5
|
+
module Mongoid
|
6
|
+
module NormalizeStrings
|
7
|
+
module ClassMethods
|
8
|
+
##
|
9
|
+
# Create normalized field for field
|
10
|
+
#
|
11
|
+
def normalize(field_name)
|
12
|
+
@normalized_fields = (@normalized_fields || Set.new).add field_name
|
13
|
+
field "#{field_name}_normalized", type: String
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Returns normalized_fields Class intance variable
|
18
|
+
#
|
19
|
+
def normalized_fields
|
20
|
+
@normalized_fields
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Adds class methods
|
26
|
+
#
|
27
|
+
def self.included(base)
|
28
|
+
base.extend(ClassMethods)
|
29
|
+
|
30
|
+
## Save normalized field value
|
31
|
+
base.send(:before_save) do
|
32
|
+
self.class.normalized_fields.each do |field_name|
|
33
|
+
if self[field_name]
|
34
|
+
self["#{field_name}_normalized"] = I18n.transliterate(self[field_name]).downcase
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mongoid-normalize-strings/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mongoid-normalize-strings"
|
8
|
+
spec.version = Mongoid::NormalizeStrings::VERSION
|
9
|
+
spec.authors = ["Rafael Jurado"]
|
10
|
+
spec.email = ["rjurado@nosolosoftware.biz"]
|
11
|
+
spec.summary = %q{Normalize fields of type string in your Mongoid models.}
|
12
|
+
spec.description = %q{Normalize fields of type string in your Mongoid models.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "i18n"
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'mongoid'
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::NormalizeStrings do
|
4
|
+
class City
|
5
|
+
include Mongoid::Document
|
6
|
+
include Mongoid::NormalizeStrings
|
7
|
+
|
8
|
+
field :name
|
9
|
+
normalize :name
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'normalize fields after create' do
|
13
|
+
city = City.create(name: 'Córdoba')
|
14
|
+
expect(city.name_normalized).to eq('cordoba')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'normalize fields after save' do
|
18
|
+
city = City.create(name: 'Córdoba')
|
19
|
+
city.name = 'Ávila'
|
20
|
+
city.save
|
21
|
+
expect(city.reload.name_normalized).to eq('avila')
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid-normalize-strings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafael Jurado
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mongoid
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Normalize fields of type string in your Mongoid models.
|
84
|
+
email:
|
85
|
+
- rjurado@nosolosoftware.biz
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/mongoid-normalize-strings.rb
|
96
|
+
- lib/mongoid-normalize-strings/normalize.rb
|
97
|
+
- lib/mongoid-normalize-strings/version.rb
|
98
|
+
- mongoid-normalize-strings.gemspec
|
99
|
+
- spec/normalize_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/support/mongoid.yml
|
102
|
+
homepage: ''
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Normalize fields of type string in your Mongoid models.
|
126
|
+
test_files:
|
127
|
+
- spec/normalize_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/mongoid.yml
|