rudash 2.8.0 → 2.8.1

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudash/at.rb +11 -10
  3. data/lib/rudash/capitalize.rb +9 -7
  4. data/lib/rudash/compact.rb +7 -5
  5. data/lib/rudash/concat.rb +10 -8
  6. data/lib/rudash/curry.rb +9 -7
  7. data/lib/rudash/difference.rb +14 -12
  8. data/lib/rudash/each.rb +12 -10
  9. data/lib/rudash/each_right.rb +14 -12
  10. data/lib/rudash/eq.rb +5 -3
  11. data/lib/rudash/every.rb +8 -6
  12. data/lib/rudash/filter.rb +25 -25
  13. data/lib/rudash/find.rb +10 -10
  14. data/lib/rudash/find_last.rb +10 -9
  15. data/lib/rudash/flip.rb +9 -7
  16. data/lib/rudash/get.rb +26 -25
  17. data/lib/rudash/head.rb +10 -8
  18. data/lib/rudash/identity.rb +5 -3
  19. data/lib/rudash/initial.rb +7 -5
  20. data/lib/rudash/intersection.rb +13 -11
  21. data/lib/rudash/is_array.rb +5 -3
  22. data/lib/rudash/is_empty.rb +9 -7
  23. data/lib/rudash/is_equal.rb +5 -3
  24. data/lib/rudash/is_hash.rb +5 -3
  25. data/lib/rudash/is_nil.rb +5 -3
  26. data/lib/rudash/is_number.rb +5 -3
  27. data/lib/rudash/is_proc.rb +5 -3
  28. data/lib/rudash/is_string.rb +9 -7
  29. data/lib/rudash/join.rb +7 -5
  30. data/lib/rudash/keys.rb +11 -9
  31. data/lib/rudash/last.rb +6 -4
  32. data/lib/rudash/map.rb +23 -22
  33. data/lib/rudash/negate.rb +11 -9
  34. data/lib/rudash/pick.rb +20 -20
  35. data/lib/rudash/reduce.rb +34 -32
  36. data/lib/rudash/reduce_right.rb +8 -6
  37. data/lib/rudash/remove.rb +12 -12
  38. data/lib/rudash/reverse.rb +9 -7
  39. data/lib/rudash/set.rb +22 -20
  40. data/lib/rudash/size.rb +8 -6
  41. data/lib/rudash/slice.rb +13 -11
  42. data/lib/rudash/some.rb +8 -6
  43. data/lib/rudash/tail.rb +6 -4
  44. data/lib/rudash/union.rb +18 -18
  45. data/lib/rudash/uniq.rb +11 -9
  46. data/lib/rudash/update.rb +10 -11
  47. data/lib/rudash/without.rb +8 -6
  48. data/lib/rudash.rb +46 -46
  49. data/lib/utils/index.rb +14 -12
  50. data/lib/utils/nested_path_creator.rb +22 -20
  51. data/lib/utils/path_resolver.rb +17 -15
  52. data/lib/utils/subset_deep_match.rb +42 -40
  53. metadata +1 -1
data/lib/utils/index.rb CHANGED
@@ -1,15 +1,17 @@
1
- module Utils
2
- def self.match_number?(str)
3
- return false if !str.is_a?(String)
4
- str.match(/^(\d)+$/)
5
- end
6
-
7
- def self.force_reverse(collection)
8
- case collection
9
- when Array then collection.reverse
10
- when Hash then collection.reverse_each.to_h
11
- when String then collection.reverse
12
- else []
1
+ module Rudash
2
+ module Utils
3
+ def self.match_number?(str)
4
+ return false if !str.is_a?(String)
5
+ str.match(/^(\d)+$/)
6
+ end
7
+
8
+ def self.force_reverse(collection)
9
+ case collection
10
+ when Array then collection.reverse
11
+ when Hash then collection.reverse_each.to_h
12
+ when String then collection.reverse
13
+ else []
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,27 +1,29 @@
1
1
  require_relative '../rudash'
2
2
  require_relative './index.rb'
3
3
 
4
- module NestedPathCreator
5
- def self.create_path_if_not_exist(object, resolved_path)
6
- path = R_.head(resolved_path)
7
- return nil if !resolved_path.is_a?(Array) || R_.is_nil?(path)
8
-
9
- path_key = Utils.match_number?(path) ? path.to_i : path.to_sym
10
- rest_paths = R_.tail(resolved_path)
11
- next_path = R_.head(rest_paths)
12
- value = R_.get(object, path)
13
-
14
- if R_.is_nil?(value) || (!value.is_a?(Hash) && !value.is_a?(Array))
15
- if next_path && Utils.match_number?(next_path)
16
- object[path_key] = []
17
- else
18
- object[path_key] = {}
4
+ module Rudash
5
+ module NestedPathCreator
6
+ def self.create_path_if_not_exist(object, resolved_path)
7
+ path = R_.head(resolved_path)
8
+ return nil if !resolved_path.is_a?(Array) || R_.is_nil?(path)
9
+
10
+ path_key = Utils.match_number?(path) ? path.to_i : path.to_sym
11
+ rest_paths = R_.tail(resolved_path)
12
+ next_path = R_.head(rest_paths)
13
+ value = R_.get(object, path)
14
+
15
+ if R_.is_nil?(value) || (!value.is_a?(Hash) && !value.is_a?(Array))
16
+ if next_path && Utils.match_number?(next_path)
17
+ object[path_key] = []
18
+ else
19
+ object[path_key] = {}
20
+ end
19
21
  end
22
+
23
+ self.create_path_if_not_exist(
24
+ R_.get(object, path),
25
+ rest_paths
26
+ )
20
27
  end
21
-
22
- self.create_path_if_not_exist(
23
- R_.get(object, path),
24
- rest_paths
25
- )
26
28
  end
27
29
  end
@@ -1,20 +1,22 @@
1
1
  require_relative '../rudash'
2
2
 
3
- module PathResolver
4
- def self.resolve(path)
5
- normalized_path = path
6
-
7
- if normalized_path.is_a?(Array)
8
- normalized_path = normalized_path.join('.')
3
+ module Rudash
4
+ module PathResolver
5
+ def self.resolve(path)
6
+ normalized_path = path
7
+
8
+ if normalized_path.is_a?(Array)
9
+ normalized_path = normalized_path.join('.')
10
+ end
11
+
12
+ filter_not_empty = -> (value) {
13
+ value != ''
14
+ }
15
+
16
+ splitted_hash = R_.filter(
17
+ normalized_path.split(/[.\[\]]/),
18
+ filter_not_empty
19
+ )
9
20
  end
10
-
11
- filter_not_empty = -> (value) {
12
- value != ''
13
- }
14
-
15
- splitted_hash = R_.filter(
16
- normalized_path.split(/[.\[\]]/),
17
- filter_not_empty
18
- )
19
21
  end
20
22
  end
@@ -4,47 +4,49 @@ require_relative '../rudash'
4
4
  # in order to give filter, some?, every? and find the ability to deep match with complex hash queries.
5
5
  # See test_filter_hashes_by_deep_hash (test/filter.rb)
6
6
 
7
- module SubsetDeepMatch
8
- def self.subset_deep_match?
9
- subset_matcher = -> (slice, collection) {
10
- match = true
11
-
12
- # If was called with two arrays then the logic will be to
13
- # check if every "slice" items exist somehow in the collection
14
- # without any order consideration.
15
- if (slice.is_a?(Array) && collection.is_a?(Array))
16
- return R_.every?(slice, -> (sliceVal) {
17
- R_.some?(collection, -> (collectionVal) {
18
- self.subset_deep_match?.(sliceVal, collectionVal)
7
+ module Rudash
8
+ module SubsetDeepMatch
9
+ def self.subset_deep_match?
10
+ subset_matcher = -> (slice, collection) {
11
+ match = true
12
+
13
+ # If was called with two arrays then the logic will be to
14
+ # check if every "slice" items exist somehow in the collection
15
+ # without any order consideration.
16
+ if (slice.is_a?(Array) && collection.is_a?(Array))
17
+ return R_.every?(slice, -> (sliceVal) {
18
+ R_.some?(collection, -> (collectionVal) {
19
+ self.subset_deep_match?.(sliceVal, collectionVal)
20
+ })
19
21
  })
20
- })
21
- end
22
-
23
- begin
24
- R_.each(collection, -> (v) {
25
- R_.each(slice, -> (value, key) {
26
- if (value.is_a?(Hash) && collection[key].is_a?(Hash))
27
- match &= self.subset_deep_match?.(value, collection[key])
28
- elsif (value.is_a?(Array) && collection[key].is_a?(Array))
29
- match &= self.subset_deep_match?.(value, collection[key])
30
- elsif (value != collection[key])
31
- match = false
32
- end
22
+ end
23
+
24
+ begin
25
+ R_.each(collection, -> (v) {
26
+ R_.each(slice, -> (value, key) {
27
+ if (value.is_a?(Hash) && collection[key].is_a?(Hash))
28
+ match &= self.subset_deep_match?.(value, collection[key])
29
+ elsif (value.is_a?(Array) && collection[key].is_a?(Array))
30
+ match &= self.subset_deep_match?.(value, collection[key])
31
+ elsif (value != collection[key])
32
+ match = false
33
+ end
34
+ })
35
+
36
+ # That was done for performance manners since
37
+ # R_.each don't stop when returning false from the proc
38
+ # so we force it to stop by throwing an exception that we catch later
39
+ # It's the same hack for JavaScript forEach function.
40
+ raise if match == false
33
41
  })
34
-
35
- # That was done for performance manners since
36
- # R_.each don't stop when returning false from the proc
37
- # so we force it to stop by throwing an exception that we catch later
38
- # It's the same hack for JavaScript forEach function.
39
- raise if match == false
40
- })
41
- rescue
42
- return false
43
- end
44
-
45
- match
46
- }
47
-
48
- subset_matcher.curry
42
+ rescue
43
+ return false
44
+ end
45
+
46
+ match
47
+ }
48
+
49
+ subset_matcher.curry
50
+ end
49
51
  end
50
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Islam Attrash