mongoid-enum-i18n 0.5.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid/enum.rb +8 -8
- data/lib/mongoid/enum/version.rb +1 -1
- data/mongoid-enum-i18n.gemspec +7 -7
- data/spec/mongoid/enum_spec.rb +17 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2697ab8dedba626fab411b37eb87ce492dd9cf
|
4
|
+
data.tar.gz: f9e98f58cf870d461faf14d9b5f0ac37f0abba88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c67b99bbf20879322f801bc54e2f308dcba542b9795f72d9c2d679866b8320be3f4d06492eb5371db27d42116830d2bc7a5693cdb19e48400b2e1df7bfffd6c
|
7
|
+
data.tar.gz: 53458955e1a2df8ea3b01bd496d9c828e246063cf975da79f05576b2a079d9c9b03f68fcdf1d3aeca58b0866a62f19fbb5cb877d2685f37028cb09e7778968b5
|
data/lib/mongoid/enum.rb
CHANGED
@@ -23,8 +23,8 @@ module Mongoid
|
|
23
23
|
set_values_constant field_name, values
|
24
24
|
|
25
25
|
create_field field_name, options, values
|
26
|
-
create_i18n_helper field_name, options
|
27
|
-
create_values_helper field_name, options
|
26
|
+
create_i18n_helper model_name, field_name, options
|
27
|
+
create_values_helper model_name, field_name, options
|
28
28
|
|
29
29
|
create_validations field_name, values, options
|
30
30
|
define_value_scopes_and_accessors field_name, values, options
|
@@ -88,30 +88,30 @@ module Mongoid
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
def create_i18n_helper(field_name, options)
|
91
|
+
def create_i18n_helper(main_model, field_name, options)
|
92
92
|
return if options[:i18n].is_a?(FalseClass)
|
93
93
|
if options[:multiple]
|
94
94
|
define_method("#{field_name}_i18n") do
|
95
95
|
return if self[field_name].blank?
|
96
96
|
self[field_name].map do |k|
|
97
|
-
I18n.translate("mongoid.enums.#{
|
97
|
+
I18n.translate("mongoid.enums.#{main_model.to_s.underscore}."\
|
98
98
|
"#{field_name}.#{k}")
|
99
99
|
end
|
100
100
|
end
|
101
101
|
else
|
102
102
|
define_method("#{field_name}_i18n") do
|
103
103
|
return if self[field_name].blank?
|
104
|
-
I18n.translate("mongoid.enums.#{
|
104
|
+
I18n.translate("mongoid.enums.#{main_model.to_s.underscore}."\
|
105
105
|
"#{field_name}.#{self[field_name]}")
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
def create_values_helper(field_name, options)
|
110
|
+
def create_values_helper(main_model, field_name, options)
|
111
111
|
return if options[:i18n].is_a?(FalseClass)
|
112
112
|
define_singleton_method("#{field_name}_values") do
|
113
|
-
I18n.translate("mongoid.enums.#{
|
114
|
-
"#{field_name}").map {
|
113
|
+
I18n.translate("mongoid.enums.#{main_model.to_s.underscore}."\
|
114
|
+
"#{field_name}").map { |k, v| [v, k] }
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
data/lib/mongoid/enum/version.rb
CHANGED
data/mongoid-enum-i18n.gemspec
CHANGED
@@ -4,19 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'mongoid/enum/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'mongoid-enum-i18n'
|
8
8
|
spec.version = Mongoid::Enum::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Nicholas Bruning', 'Marcos Piccinini']
|
10
|
+
spec.email = ['nicholas@bruning.com.au']
|
11
11
|
spec.description = %q{Heavily inspired by DDH's ActiveRecord::Enum, this little library is there to help you cut down the cruft in your models and make the world a happier place at the same time.}
|
12
12
|
spec.summary = %q{Sweet enum sugar for your Mongoid documents}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/thetron/mongoid-enum'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_runtime_dependency
|
21
|
+
spec.add_runtime_dependency 'mongoid', '> 4.0.0'
|
22
22
|
end
|
data/spec/mongoid/enum_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# Test Class
|
3
4
|
class User
|
4
5
|
include Mongoid::Document
|
5
6
|
include Mongoid::Enum
|
@@ -11,6 +12,9 @@ class User
|
|
11
12
|
required: false
|
12
13
|
end
|
13
14
|
|
15
|
+
class Admin < User
|
16
|
+
end
|
17
|
+
|
14
18
|
describe Mongoid::Enum do
|
15
19
|
let(:klass) { User }
|
16
20
|
let(:instance) { User.new }
|
@@ -77,7 +81,7 @@ describe Mongoid::Enum do
|
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
80
|
-
describe 'accessors'do
|
84
|
+
describe 'accessors' do
|
81
85
|
context 'when singular' do
|
82
86
|
describe 'setter' do
|
83
87
|
it 'accepts strings' do
|
@@ -135,7 +139,7 @@ describe Mongoid::Enum do
|
|
135
139
|
end
|
136
140
|
|
137
141
|
it 'accepts arrays of strings' do
|
138
|
-
instance.roles = %w(
|
142
|
+
instance.roles = %w(author editor)
|
139
143
|
instance.save
|
140
144
|
puts instance.errors.full_messages
|
141
145
|
instance.reload
|
@@ -143,12 +147,13 @@ describe Mongoid::Enum do
|
|
143
147
|
expect(instance.roles).to include(:editor)
|
144
148
|
end
|
145
149
|
|
146
|
-
it 'accepts arrays of symbols'
|
150
|
+
it 'accepts arrays of symbols' do
|
147
151
|
instance.roles = [:author, :editor]
|
148
152
|
expect(instance.roles).to include(:author)
|
149
153
|
expect(instance.roles).to include(:editor)
|
150
154
|
end
|
151
155
|
end
|
156
|
+
|
152
157
|
describe '{{value}}!' do
|
153
158
|
context 'when field is nil' do
|
154
159
|
it 'creates an array containing the value' do
|
@@ -267,5 +272,14 @@ describe Mongoid::Enum do
|
|
267
272
|
expect(User.status_values)
|
268
273
|
.to eq([['Awaiting Approval', :awaiting_approval]])
|
269
274
|
end
|
275
|
+
|
276
|
+
it 'should use class where it was coded into' do
|
277
|
+
expect(Admin.status_values)
|
278
|
+
.to eq([['Awaiting Approval', :awaiting_approval]])
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should use class where it was coded into' do
|
282
|
+
expect(Admin.new.status_i18n).to eq('Awaiting Approval')
|
283
|
+
end
|
270
284
|
end
|
271
285
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-enum-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Bruning
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.6.6
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Sweet enum sugar for your Mongoid documents
|