deeply_enumerable 0.9.1 → 0.9.2

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
- SHA1:
3
- metadata.gz: 24ae2c2a4300e316b42bf56818be9c29161b723e
4
- data.tar.gz: b50f1da16577e2839c94e47e3a42236325474249
2
+ SHA256:
3
+ metadata.gz: eae0841086c0da8d042453e9a3bbb184099e134b1af550b936361df36f4c1503
4
+ data.tar.gz: 95851be8f55f8da1b518b409db283394672f94fe1995cf74bd5bbb5e1054f17f
5
5
  SHA512:
6
- metadata.gz: 65a9ff36a5af05c00542de722bfd61afa4035c6900d32e4e54a91ce58e1b018b00578f5dbf13ce28efb7cec0d9c7619c4e21c0609a665100814212d3b000cb4c
7
- data.tar.gz: 70b667500145abac357d1f4af3dc0cfd90c66ddf6f3e0f7470dfff2122933906f21b9d53bfe51862eef42d4060d290643026321548175d633abf299e729f56f7
6
+ metadata.gz: 175c6f0ebf20d033532cbe171d532aa24f9461facb8951f630fdfd672710b7f61994374b6f5ecd3f7b944ba039d3bd67012809e36769cd3a582ef1a4fa768d58
7
+ data.tar.gz: 41fa00c185d23a48c8c89bcd5d42d076a4e555643453bd382d2031f335466a3949106555b09b8d72a5db5f94e77d68f0413916a114eec2e24c60d23e9067d9e8
@@ -1,8 +1,8 @@
1
1
  require_relative 'enumerable'
2
2
 
3
3
  module DeeplyEnumerable
4
- module ArrayExtension
5
- def self.included klass
4
+ module ArrayExtensionklass
5
+ def self.included
6
6
  klass.class_eval do
7
7
  include DeeplyEnumerable::Enumerable
8
8
  end
@@ -10,6 +10,8 @@ module DeeplyEnumerable
10
10
 
11
11
  def deep_compact!(remove_emptied_elements = true, remove_empty_elements = remove_emptied_elements)
12
12
  each.with_index do |value, index|
13
+ next if unenumerable_object?(value)
14
+
13
15
  value = rebuild(value) unless value.respond_to?(:reverse_deep_merge)
14
16
  compact_method = %i[deep_compact! deep_compact compact! compact].detect{ |m| value.respond_to?(m) }
15
17
  next unless compact_method
@@ -1,5 +1,7 @@
1
1
  module DeeplyEnumerable
2
2
  module Enumerable
3
+ UNENUMERABLE = ['ActiveRecord::Relation']
4
+
3
5
  def self.included(klass)
4
6
  klass.extend(ClassMethods)
5
7
  end
@@ -29,6 +31,10 @@ module DeeplyEnumerable
29
31
 
30
32
  private
31
33
 
34
+ def unenumerable
35
+ @unenumerable ||= UNENUMERABLE.map(&:safe_constantize).compact
36
+ end
37
+
32
38
  def check_object_class(object)
33
39
  raise TypeError, "object must be a #{superclass.name}" unless object.kind_of?(superclass)
34
40
  end
@@ -37,5 +43,9 @@ module DeeplyEnumerable
37
43
  def rebuild(object)
38
44
  self.class.rebuild(object)
39
45
  end
46
+
47
+ def unenumerable_object?(object)
48
+ next if self.class.unenumerable.any? { |unenumerable_klass| object.is_a?(unenumerable_klass) }
49
+ end
40
50
  end
41
51
  end
@@ -31,11 +31,14 @@ module DeeplyEnumerable
31
31
 
32
32
  def deep_compact!(remove_emptied_elements = true, remove_empty_elements = remove_emptied_elements)
33
33
  each do |key, value|
34
+ next if unenumerable_object?(value)
35
+
34
36
  value = rebuild(value) unless value.respond_to?(:reverse_deep_merge)
35
37
  compact_method = %i[deep_compact! deep_compact compact! compact].detect{ |m| value.respond_to?(m) }
36
38
  next unless compact_method
37
39
 
38
40
  original_empty = value.respond_to?(:empty?) ? value.empty? : value.respond_to?(:none?) ? value.none? : false
41
+ debugger
39
42
  compact_value = value.send(*[compact_method].concat(value.method(compact_method).parameters.collect { |_,param| binding.local_variable_get(param) } ).compact) || value
40
43
  compact_empty = compact_value.respond_to?(:empty?) ? compact_value.empty? : compact_value.respond_to?(:none?) ? compact_value.none? : false
41
44
 
@@ -1,3 +1,3 @@
1
1
  module DeeplyEnumerable
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deeply_enumerable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - chaunce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-06 00:00:00.000000000 Z
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -59,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.6.14
62
+ rubygems_version: 3.0.6
64
63
  signing_key:
65
64
  specification_version: 4
66
65
  summary: recusrive support for enumerable operations