mongoid_localized_fields_fallback_patch 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mongoid_localized_fields_fallback_patch.rb +33 -0
- data/lib/mongoid_localized_fields_fallback_patch/version.rb +3 -0
- data/mongoid_localized_fields_fallback_patch.gemspec +30 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7aea2007c3c65ad80ce7dc9ed87d2c9f4d20f3008297ee9a880571ec998c1a28
|
4
|
+
data.tar.gz: f1e9d5003fdc2e0b6907a2e0cf5f407d896d94ad6b511b29f8b0c23adf04da16
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a705e90a476289cba7742aec68a8feb230cec9b500ca8b14ca05d417092132555700c931d9af7531e558861715e67547dd5d8f7594deb4d0d44b91450e44bfb5
|
7
|
+
data.tar.gz: 7b19a8dfc7e23accc5a4ea6bde51544693302ce226f9b957827f9c3aa7f1451ab6e64dd294761a9b248a9b6749fce4628ff8f9b70df204a20b0909170f5a6c13
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
script: 'bundle exec rake'
|
4
|
+
rvm:
|
5
|
+
- 2.5.1
|
6
|
+
before_install:
|
7
|
+
- gem install bundler -v 1.16.1
|
8
|
+
notifications:
|
9
|
+
email:
|
10
|
+
recipients:
|
11
|
+
- tomas.celizna@gmail.com
|
12
|
+
- a@asgerbehnckejacobsen.dk
|
13
|
+
on_failure: change
|
14
|
+
on_success: never
|
15
|
+
|
16
|
+
matrix:
|
17
|
+
include:
|
18
|
+
- rvm: 2.3.3
|
19
|
+
env: MONGOID_VERSION=6
|
20
|
+
- rvm: 2.5.1
|
21
|
+
env: MONGOID_VERSION=7
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in mongoid_localized_fields_fallback_patch.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
case version = ENV['MONGOID_VERSION'] || '~> 7.0'
|
9
|
+
when /7/ then gem 'mongoid', '~> 7.0'
|
10
|
+
when /6/ then gem 'mongoid', '~> 6.0'
|
11
|
+
else gem 'mongoid', version
|
12
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Tomáš Celizna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 asgerb
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Mongoid Localized Fields Fallback Patch
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tomasc/mongoid_localized_fields_fallback_patch.svg)](https://travis-ci.org/tomasc/mongoid_localized_fields_fallback_patch) [![Gem Version](https://badge.fury.io/rb/mongoid_localized_fields_fallback_patch.svg)](http://badge.fury.io/rb/mongoid_localized_fields_fallback_patch) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid_localized_fields_fallback_patch.svg)](https://coveralls.io/r/tomasc/mmongoid_localized_fields_fallback_patch)
|
4
|
+
|
5
|
+
A patch for [Mongoid](https://github.com/mongodb/mongoid) localized fields
|
6
|
+
making it fallback through locale values that are not only `#nil?` but also
|
7
|
+
`#blank?`.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'mongoid_localized_fields_fallback_patch'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install mongoid_localized_fields_fallback_patch
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Nothing, just add `gem 'mongoid_localized_fields_fallback_patch'` to your Gemfile
|
28
|
+
and you're good to go.
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
33
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
34
|
+
prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
37
|
+
release a new version, update the version number in `version.rb`, and then run
|
38
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
39
|
+
git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/mongoid_localized_fields_fallback_patch.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mongoid_localized_fields_fallback_patch"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "mongoid_localized_fields_fallback_patch/version"
|
2
|
+
|
3
|
+
module MongoidLocalizedFieldsFallbackPatch
|
4
|
+
def lookup(object)
|
5
|
+
locale = ::I18n.locale
|
6
|
+
|
7
|
+
value = localized_value(object, locale)
|
8
|
+
|
9
|
+
return value if [true, false].include?(value)
|
10
|
+
return value unless value.blank?
|
11
|
+
return unless fallbacks? && ::I18n.respond_to?(:fallbacks)
|
12
|
+
|
13
|
+
fallback_locale = ::I18n.fallbacks[locale].find do |loc|
|
14
|
+
value = localized_value(object, loc)
|
15
|
+
loc if [true, false].include?(value)
|
16
|
+
loc unless (value).blank?
|
17
|
+
end
|
18
|
+
|
19
|
+
return localized_value(object, fallback_locale)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def localized_value(object, locale)
|
25
|
+
if object.key?(locale.to_s)
|
26
|
+
object[locale.to_s]
|
27
|
+
elsif object.key?(locale)
|
28
|
+
object[locale]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Mongoid::Fields::Localized.send(:prepend, MongoidLocalizedFieldsFallbackPatch)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'mongoid_localized_fields_fallback_patch/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mongoid_localized_fields_fallback_patch'
|
7
|
+
spec.version = MongoidLocalizedFieldsFallbackPatch::VERSION
|
8
|
+
spec.authors = ['Tomas Celizna', 'Asger Behncke Jacobsen']
|
9
|
+
spec.email = ['tomas.celizna@gmail.com', 'a@asgerbehnckejacobsen.dk']
|
10
|
+
|
11
|
+
spec.summary = 'A patch for mongoid localized fields, making it fallback through locale values that are not only `:nil?` but also `:blank?`.'
|
12
|
+
spec.homepage = 'https://github.com/tomasc/mongoid_localized_fields_fallback_patch'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'mongoid', '>= 6.0', '< 8.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'coveralls'
|
26
|
+
spec.add_development_dependency 'guard'
|
27
|
+
spec.add_development_dependency 'guard-minitest'
|
28
|
+
spec.add_development_dependency 'minitest'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_localized_fields_fallback_patch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Celizna
|
8
|
+
- Asger Behncke Jacobsen
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-08-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '6.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '8.0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '6.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '8.0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: coveralls
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: guard-minitest
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: minitest
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rake
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
description:
|
119
|
+
email:
|
120
|
+
- tomas.celizna@gmail.com
|
121
|
+
- a@asgerbehnckejacobsen.dk
|
122
|
+
executables: []
|
123
|
+
extensions: []
|
124
|
+
extra_rdoc_files: []
|
125
|
+
files:
|
126
|
+
- ".gitignore"
|
127
|
+
- ".travis.yml"
|
128
|
+
- CHANGELOG.md
|
129
|
+
- Gemfile
|
130
|
+
- LICENSE
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
- Rakefile
|
134
|
+
- bin/console
|
135
|
+
- bin/setup
|
136
|
+
- lib/mongoid_localized_fields_fallback_patch.rb
|
137
|
+
- lib/mongoid_localized_fields_fallback_patch/version.rb
|
138
|
+
- mongoid_localized_fields_fallback_patch.gemspec
|
139
|
+
homepage: https://github.com/tomasc/mongoid_localized_fields_fallback_patch
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.7.6
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: A patch for mongoid localized fields, making it fallback through locale values
|
163
|
+
that are not only `:nil?` but also `:blank?`.
|
164
|
+
test_files: []
|