enum_ext 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/enum_ext.rb +12 -13
- data/lib/enum_ext/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e124aa3c4dcc444a79313a06d79aa55862a58c065a00b399797413e11ca13a
|
4
|
+
data.tar.gz: ba28311cd931ba1233585407f8532c5026a7dee51b3a695c3c36a8fd675ec27e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 103d98798be494d1fc9b8354dc84b4bad405d282c3aa83be42cee4800775bc20b848294d913cf682be5e7e25db03bb34fb402bd296e9376d461e1cd29a369b3f
|
7
|
+
data.tar.gz: '081f7581316c5904826f0daf2aa023a8a959900c0cbe4ea3d16a64831602d17ff5b267260d8ff97da62e4c83676a07ae28996b767fd7dd120c73dce7484d09f5'
|
data/CHANGELOG.md
CHANGED
data/lib/enum_ext.rb
CHANGED
@@ -69,26 +69,25 @@ module EnumExt
|
|
69
69
|
# ext_enum_sets :status, {
|
70
70
|
# outside_wharehouse: ( delivery_set_statuses - in_warehouse_statuses )... any other array operations like &, + and so can be used
|
71
71
|
# }
|
72
|
-
def ext_enum_sets( enum_name, options )
|
72
|
+
def ext_enum_sets( enum_name, options = {} )
|
73
73
|
enum_plural = enum_name.to_s.pluralize
|
74
74
|
|
75
75
|
self.instance_eval do
|
76
|
+
# with_enums scope
|
77
|
+
scope "with_#{enum_plural}", -> (sets_arr) {
|
78
|
+
where( enum_name => self.send( enum_plural ).slice(
|
79
|
+
*sets_arr.map{|set_name| self.try( "#{set_name}_#{enum_plural}" ) || set_name }.flatten.uniq.map(&:to_s) ).values )
|
80
|
+
} unless respond_to?("with_#{enum_plural}")
|
81
|
+
|
82
|
+
# without_enums scope
|
83
|
+
scope "without_#{enum_plural}", -> (sets_arr) {
|
84
|
+
where.not( id: self.send("with_#{enum_plural}", sets_arr) )
|
85
|
+
} unless respond_to?("without_#{enum_plural}")
|
86
|
+
|
76
87
|
options.each do |set_name, enum_vals|
|
77
88
|
# set_name scope
|
78
89
|
scope set_name, -> { where( enum_name => self.send( enum_plural ).slice( *enum_vals.map(&:to_s) ).values ) }
|
79
90
|
|
80
|
-
# with_enums scope
|
81
|
-
scope "with_#{enum_plural}", -> (sets_arr) {
|
82
|
-
where( enum_name => self.send( enum_plural ).slice(
|
83
|
-
*sets_arr.map{|set_name| self.try( "#{set_name}_#{enum_plural}" ) || set_name }.flatten.uniq.map(&:to_s) ).values )
|
84
|
-
} unless respond_to?("with_#{enum_plural}")
|
85
|
-
|
86
|
-
# without_enums scope
|
87
|
-
scope "without_#{enum_plural}", -> (sets_arr) {
|
88
|
-
where.not( id: self.send("with_#{enum_plural}", sets_arr) )
|
89
|
-
} unless respond_to?("without_#{enum_plural}")
|
90
|
-
|
91
|
-
|
92
91
|
# class.enum_set_values
|
93
92
|
define_singleton_method( "#{set_name}_#{enum_plural}" ) do
|
94
93
|
enum_vals
|
data/lib/enum_ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|