mongoid_enum_mapper 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +30 -0
- data/README.md +1 -0
- data/gemfiles/mongoid_40.gemfile +11 -0
- data/gemfiles/mongoid_50.gemfile +11 -0
- data/gemfiles/mongoid_51.gemfile +11 -0
- data/gemfiles/mongoid_60.gemfile +12 -0
- data/gemfiles/mongoid_61.gemfile +11 -0
- data/lib/mongoid/enum_mapper/define_enum.rb +24 -21
- data/lib/mongoid/enum_mapper/version.rb +1 -1
- data/mongoid_enum_mapper.gemspec +1 -1
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d0a0051e60354703c9c5043588cf66eef8f026947d6f4a967ae478fa8e1bb14
|
4
|
+
data.tar.gz: e20189a9446da51c696ba9aff909b655d91d33904643b945606467fba84d899f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a41c6b7649a65bc235a9fbfb37b2499ef66813854680f8356a4f7347a37ae7c58a91ede1924310099459349aef7a0789bdf0e6964e3530d15039d92b1a15485
|
7
|
+
data.tar.gz: 1e958ee4564771a0e064fe9a195de18cd438eb590aafc235b2dc72f387c0aec5bc0f9f7034529da2b24ffa740f0fbe906ff0d8e70be32b1edc30788e7acfb99a
|
data/.travis.yml
CHANGED
@@ -7,6 +7,36 @@ rvm:
|
|
7
7
|
- 2.2
|
8
8
|
- 2.3
|
9
9
|
- 2.4
|
10
|
+
- 2.5
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/mongoid_61.gemfile
|
13
|
+
- gemfiles/mongoid_60.gemfile
|
14
|
+
- gemfiles/mongoid_51.gemfile
|
15
|
+
- gemfiles/mongoid_50.gemfile
|
16
|
+
- gemfiles/mongoid_40.gemfile
|
17
|
+
matrix:
|
18
|
+
exclude:
|
19
|
+
- rvm: 2.5
|
20
|
+
gemfile: gemfiles/mongoid_51.gemfile
|
21
|
+
- rvm: 2.5
|
22
|
+
gemfile: gemfiles/mongoid_50.gemfile
|
23
|
+
- rvm: 2.5
|
24
|
+
gemfile: gemfiles/mongoid_40.gemfile
|
25
|
+
- rvm: 2.4
|
26
|
+
gemfile: gemfiles/mongoid_51.gemfile
|
27
|
+
- rvm: 2.4
|
28
|
+
gemfile: gemfiles/mongoid_50.gemfile
|
29
|
+
- rvm: 2.4
|
30
|
+
gemfile: gemfiles/mongoid_40.gemfile
|
31
|
+
- rvm: 2.1
|
32
|
+
gemfile: gemfiles/mongoid_61.gemfile
|
33
|
+
- rvm: 2.0
|
34
|
+
gemfile: gemfiles/mongoid_61.gemfile
|
35
|
+
- rvm: 2.1
|
36
|
+
gemfile: gemfiles/mongoid_60.gemfile
|
37
|
+
cache: bundler
|
38
|
+
services:
|
39
|
+
- mongodb
|
10
40
|
before_install:
|
11
41
|
- gem install bundler
|
12
42
|
- gem update --system
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/mongoid_enum_mapper.svg)](https://badge.fury.io/rb/mongoid_enum_mapper)
|
1
2
|
[![Maintainability](https://api.codeclimate.com/v1/badges/919d0459a7ffdfa9a221/maintainability)](https://codeclimate.com/github/berniechiu/mongoid_enum_mapper/maintainability)
|
2
3
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/919d0459a7ffdfa9a221/test_coverage)](https://codeclimate.com/github/berniechiu/mongoid_enum_mapper/test_coverage)
|
3
4
|
[![Build Status](https://travis-ci.org/berniechiu/mongoid_enum_mapper.svg?branch=master)](https://travis-ci.org/berniechiu/mongoid_enum_mapper)
|
@@ -2,35 +2,38 @@ module Mongoid
|
|
2
2
|
module EnumMapper
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
reset_enum_mapping_cache
|
12
|
-
self
|
13
|
-
end
|
5
|
+
included do
|
6
|
+
def reload
|
7
|
+
super
|
8
|
+
reset_enum_mapping_cache
|
9
|
+
self
|
10
|
+
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
reset_enum_mapping_cache(enum_field: field)
|
12
|
+
def reset_enum_mapping_cache(enum_field: nil, key: nil)
|
13
|
+
if enum_field
|
14
|
+
# Reset certain enum field
|
15
|
+
enum_mapper = self.class.const_get(enum_field.to_s.upcase)
|
16
|
+
key ||= enum_mapper.key(self[:"#{enum_field}"]) # If key not found, grep from current db value
|
17
|
+
enum_status = enum_mapper[key]
|
18
|
+
reset_enum_instance_cache(enum_field, status: enum_status)
|
19
|
+
enum_status ? (self[enum_field] = enum_status) : self[enum_field]
|
20
|
+
else
|
21
|
+
# Reset all enum field
|
22
|
+
self.class.current_enums.each { |field| reset_enum_mapping_cache(enum_field: field) }
|
27
23
|
end
|
28
24
|
end
|
25
|
+
|
26
|
+
def reset_enum_instance_cache(field, status: nil)
|
27
|
+
instance_variable_set(:"@#{field}", nil) if self.status != status
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
31
|
module ClassMethods
|
32
|
+
attr_reader :current_enums
|
33
|
+
|
32
34
|
def define_enum(enum_field, enum_mapping = {})
|
33
35
|
field :"#{enum_field}", type: Integer, default: 0
|
36
|
+
|
34
37
|
set_enum_mapping_constant(enum_field, enum_mapping)
|
35
38
|
set_current_enum_fields(enum_field)
|
36
39
|
|
data/mongoid_enum_mapper.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_enum_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernie Chiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "<="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 6.2.1
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "<="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 6.2.1
|
89
89
|
description: Enum mapper for Mongoid field
|
90
90
|
email:
|
91
91
|
- bernie_chiu@hotmail.com
|
@@ -101,6 +101,11 @@ files:
|
|
101
101
|
- Rakefile
|
102
102
|
- bin/console
|
103
103
|
- bin/setup
|
104
|
+
- gemfiles/mongoid_40.gemfile
|
105
|
+
- gemfiles/mongoid_50.gemfile
|
106
|
+
- gemfiles/mongoid_51.gemfile
|
107
|
+
- gemfiles/mongoid_60.gemfile
|
108
|
+
- gemfiles/mongoid_61.gemfile
|
104
109
|
- lib/enum_mapper.rb
|
105
110
|
- lib/mongoid/enum_mapper/define_enum.rb
|
106
111
|
- lib/mongoid/enum_mapper/version.rb
|