mongoid-enum-i18n 0.3.3 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05a4d304aae8d23f8878a962cc00c64ddb1c7b3d
4
- data.tar.gz: 64586879201fcec998fa0777c1ade4082cae546b
3
+ metadata.gz: 087290bda960e33c3f14b3387ce59ad351f30593
4
+ data.tar.gz: 1ec63ea56be4a178b7b85778fb14b055c9c984c1
5
5
  SHA512:
6
- metadata.gz: 96d4daf3bef66e8cd4932e586e01b06e3e871f1a0693a06feff4a773ffc7acce2f8b02884b3bb71f2148717fd06485ebc2651f4fcd790cb191008d05c0907bc9
7
- data.tar.gz: c12600730ef0df5f45f9767035a31313fc93045affb8cfedbf4ac6a080efe2dbbf5a1c3d00e7546ba4dc65e9027ca2a35243eaa161e4a9b99e31047c92cc50c0
6
+ metadata.gz: ea8f8e9c035c0a0a4215d634b9b6baa8fca03fcfe5d0963d6b3c6d3fa15bb5c01c7628ab5bfe64caa26edab87ae34143ed4bf95953a6d048222752cf7d05086d
7
+ data.tar.gz: f1ee6f58f2503852e2f09171c11a853dfb5a5d897f1979dcc2ae7b0315d66d14b281a2c742cdf340ecea625fb2678b96026d53a6182a7cf03adcea16f255db3d
data/Gemfile CHANGED
@@ -12,5 +12,5 @@ group :test do
12
12
  gem 'guard-rubocop'
13
13
  gem 'rspec', '>= 3.2.0'
14
14
  gem 'codeclimate-test-reporter', require: nil
15
- gem 'mongoid-rspec', git: 'https://github.com/nofxx/mongoid-rspec'
15
+ gem 'mongoid-rspec' #, git: 'https://github.com/nofxx/mongoid-rspec'
16
16
  end
data/lib/mongoid/enum.rb CHANGED
@@ -28,8 +28,11 @@ module Mongoid
28
28
 
29
29
  create_validations field_name, values, options
30
30
  define_value_scopes_and_accessors field_name, values, options
31
- return unless options[:multiple]
32
- define_array_field_writer field_name
31
+ if options[:multiple]
32
+ define_array_field_writer field_name
33
+ else
34
+ define_field_writer field_name
35
+ end
33
36
  end
34
37
 
35
38
  private
@@ -50,11 +53,11 @@ module Mongoid
50
53
  def create_field(field_name, options, values)
51
54
  type = options[:multiple] && Array || Symbol
52
55
  default = \
53
- if options.key?(:default)
54
- options[:default]
55
- else
56
- options[:multiple] ? [] : values.first
57
- end
56
+ if options.key?(:default)
57
+ options[:default]
58
+ else
59
+ options[:multiple] ? [] : values.first
60
+ end
58
61
  field field_name, type: type, default: default
59
62
  end
60
63
 
@@ -64,6 +67,13 @@ module Mongoid
64
67
  end
65
68
  end
66
69
 
70
+ def define_field_writer(field_name)
71
+ define_method("#{field_name}=") do |val|
72
+ val = nil if val.respond_to?(:empty?) && val.empty?
73
+ write_attribute(field_name, val)
74
+ end
75
+ end
76
+
67
77
  def create_validations(field_name, values, options)
68
78
  return unless options[:validate]
69
79
  if options[:multiple]
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  # VERSION
3
3
  module Enum
4
- VERSION = '0.3.3'
4
+ VERSION = '0.5.0'
5
5
  end
6
6
  end
@@ -85,6 +85,11 @@ describe Mongoid::Enum do
85
85
  expect(instance.status).to eq :banned
86
86
  end
87
87
 
88
+ it 'accepts empty string as nil' do
89
+ instance.status = ''
90
+ expect(instance.status).to be_nil
91
+ end
92
+
88
93
  it 'accepts symbols' do
89
94
  instance.status = :banned
90
95
  expect(instance.status).to eq :banned
@@ -244,6 +249,11 @@ describe Mongoid::Enum do
244
249
  expect(instance.status_i18n).to be_nil
245
250
  end
246
251
 
252
+ it 'should have a helper to translate the enum with empty' do
253
+ instance.status = ''
254
+ expect(instance.status_i18n).to be_nil
255
+ end
256
+
247
257
  it 'should return nil when enum is nil' do
248
258
  expect(instance.roles_i18n).to be_nil
249
259
  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.3.3
4
+ version: 0.5.0
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: 2015-09-22 00:00:00.000000000 Z
12
+ date: 2016-01-26 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.4.8
76
+ rubygems_version: 2.5.1
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Sweet enum sugar for your Mongoid documents