enum_ext 0.4.2 → 0.4.3

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
  SHA256:
3
- metadata.gz: 364abab1ad0b759be15eb2353fbbca5d483d13ea65e4d9d9c407cdb0a9a7265d
4
- data.tar.gz: 3653c710a34c0d02d1568e961ce667e6b0c005285b04f56a1debe2737944cdbe
3
+ metadata.gz: 74e124aa3c4dcc444a79313a06d79aa55862a58c065a00b399797413e11ca13a
4
+ data.tar.gz: ba28311cd931ba1233585407f8532c5026a7dee51b3a695c3c36a8fd675ec27e
5
5
  SHA512:
6
- metadata.gz: d6960e5b712f3f48a84d5e746fa49c3354a78c433547750c9b2dd324da8a7b021d09eb8bdcfdc73d67e38aca67e4771b6fe8c1f6a57958b93db4b14b03e0780e
7
- data.tar.gz: 7aa13f57d737196c809f05a8cb4cd1ee193a6ac06ff3516fa022af9210f789f461fd35c636fb524dcf777926643af53e231c9eb17ad9daad558866a699d9da6c
6
+ metadata.gz: 103d98798be494d1fc9b8354dc84b4bad405d282c3aa83be42cee4800775bc20b848294d913cf682be5e7e25db03bb34fb402bd296e9376d461e1cd29a369b3f
7
+ data.tar.gz: '081f7581316c5904826f0daf2aa023a8a959900c0cbe4ea3d16a64831602d17ff5b267260d8ff97da62e4c83676a07ae28996b767fd7dd120c73dce7484d09f5'
@@ -1,3 +1,6 @@
1
+ # 0.4.3
2
+ * ext_enum_sets now can go without options just to define with and without scopes
3
+
1
4
  # 0.4.2
2
5
  * bugfix for localize_enum multiple call
3
6
  * test added for 0.4.1 ver funcitonality ( multiple times humanize_enum calls )
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EnumExt
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
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.2
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-04 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord