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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26b3b43fed1a77165990d18dff6678c7646228bb66ec14c1c8dc18dea6faf120
4
- data.tar.gz: '06683302772ad3c1ea70ad16cd0e59eb33bdc0bd7146940c7e0b5f6e208f5d9b'
3
+ metadata.gz: 5d0a0051e60354703c9c5043588cf66eef8f026947d6f4a967ae478fa8e1bb14
4
+ data.tar.gz: e20189a9446da51c696ba9aff909b655d91d33904643b945606467fba84d899f
5
5
  SHA512:
6
- metadata.gz: 1be85951a46d41c97b9bf4c4bfdba4373f2838f4d0b070b454eb39348e1a03f09b8cf690a816e380cd69dd8dbfd7d8a7ac675d637842a8acbf445c6c2cc1c0a9
7
- data.tar.gz: d4d75bf8d5513629704768e5916097ec69c9b76d0c77ae511a5a716f5536f4d8bd6f8f6944be5026e5f88c07deb2a2315eb8f35ab477ab45e4334ca82994ea92
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)
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+
7
+ gemspec path: '../'
8
+
9
+ group :test do
10
+ gem 'simplecov', '~> 0.15.1'
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'mongoid', '~> 5.0.0'
6
+
7
+ gemspec path: '../'
8
+
9
+ group :test do
10
+ gem 'simplecov', '~> 0.15.1'
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'mongoid', '~> 5.1.0'
6
+
7
+ gemspec path: '../'
8
+
9
+ group :test do
10
+ gem 'simplecov', '~> 0.15.1'
11
+ end
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'mongoid', '~> 6.0.0'
6
+
7
+ gemspec path: '../'
8
+
9
+ group :test do
10
+ gem 'simplecov', '~> 0.15.1'
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'mongoid', '~> 6.1.0'
6
+
7
+ gemspec path: '../'
8
+
9
+ group :test do
10
+ gem 'simplecov', '~> 0.15.1'
11
+ end
@@ -2,35 +2,38 @@ module Mongoid
2
2
  module EnumMapper
3
3
  extend ActiveSupport::Concern
4
4
 
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- def reload
10
- super
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
- def reset_enum_mapping_cache(enum_field: nil, key: nil)
16
- if enum_field
17
- # Reset certain enum field
18
- enum_mapper = self.class.const_get(enum_field.to_s.upcase)
19
- key ||= enum_mapper.key(self[:"#{enum_field}"]) # If key not found, grep from current db value
20
- return self[enum_field] unless enum_mapper[key]
21
- instance_variable_set(:"@#{enum_field}", nil)
22
- self[enum_field] = enum_mapper[key]
23
- else
24
- # Reset all enum field
25
- self.class.instance_variable_get(:'@current_enums').each do |field|
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
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module EnumMapper
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "minitest", "~> 5.0"
36
36
  spec.add_development_dependency "pry-byebug", "~> 3.5", ">= 3.5.1"
37
37
 
38
- spec.add_dependency "mongoid", "<= 5.2.1"
38
+ spec.add_dependency "mongoid", "<= 6.2.1"
39
39
  end
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.5.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-14 00:00:00.000000000 Z
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: 5.2.1
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: 5.2.1
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