rudash 2.17.1 → 2.17.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudash/at.rb +8 -8
  3. data/lib/rudash/capitalize.rb +4 -4
  4. data/lib/rudash/chain.rb +4 -4
  5. data/lib/rudash/compact.rb +5 -5
  6. data/lib/rudash/concat.rb +9 -9
  7. data/lib/rudash/curry.rb +4 -4
  8. data/lib/rudash/difference.rb +11 -11
  9. data/lib/rudash/drop_right.rb +9 -9
  10. data/lib/rudash/each.rb +8 -8
  11. data/lib/rudash/each_right.rb +10 -10
  12. data/lib/rudash/eq.rb +4 -4
  13. data/lib/rudash/every.rb +5 -5
  14. data/lib/rudash/filter.rb +23 -23
  15. data/lib/rudash/find.rb +7 -7
  16. data/lib/rudash/find_last.rb +7 -7
  17. data/lib/rudash/flip.rb +10 -10
  18. data/lib/rudash/flow.rb +11 -11
  19. data/lib/rudash/flow_right.rb +6 -6
  20. data/lib/rudash/get.rb +22 -22
  21. data/lib/rudash/group_by.rb +17 -17
  22. data/lib/rudash/head.rb +8 -8
  23. data/lib/rudash/identity.rb +4 -4
  24. data/lib/rudash/initial.rb +6 -6
  25. data/lib/rudash/intersection.rb +10 -10
  26. data/lib/rudash/is_array.rb +4 -4
  27. data/lib/rudash/is_empty.rb +9 -9
  28. data/lib/rudash/is_equal.rb +4 -4
  29. data/lib/rudash/is_hash.rb +4 -4
  30. data/lib/rudash/is_nil.rb +4 -4
  31. data/lib/rudash/is_number.rb +4 -4
  32. data/lib/rudash/is_string.rb +4 -4
  33. data/lib/rudash/join.rb +6 -6
  34. data/lib/rudash/keys.rb +11 -11
  35. data/lib/rudash/last.rb +5 -5
  36. data/lib/rudash/map.rb +19 -19
  37. data/lib/rudash/negate.rb +8 -8
  38. data/lib/rudash/pick.rb +16 -16
  39. data/lib/rudash/range.rb +43 -43
  40. data/lib/rudash/reduce.rb +29 -29
  41. data/lib/rudash/reduce_right.rb +5 -5
  42. data/lib/rudash/reject.rb +13 -13
  43. data/lib/rudash/remove.rb +9 -9
  44. data/lib/rudash/reverse.rb +9 -9
  45. data/lib/rudash/set.rb +20 -20
  46. data/lib/rudash/size.rb +5 -5
  47. data/lib/rudash/slice.rb +12 -12
  48. data/lib/rudash/some.rb +5 -5
  49. data/lib/rudash/tail.rb +5 -5
  50. data/lib/rudash/take.rb +11 -11
  51. data/lib/rudash/union.rb +15 -15
  52. data/lib/rudash/uniq.rb +11 -11
  53. data/lib/rudash/unset.rb +30 -30
  54. data/lib/rudash/update.rb +9 -9
  55. data/lib/rudash/without.rb +5 -5
  56. data/lib/rudash.rb +54 -54
  57. data/lib/utils/chain_wrapper.rb +18 -18
  58. data/lib/utils/dynamic_args_count.rb +10 -10
  59. data/lib/utils/index.rb +17 -17
  60. data/lib/utils/nested_path_creator.rb +24 -24
  61. data/lib/utils/path_resolver.rb +17 -17
  62. data/lib/utils/subset_deep_match.rb +41 -41
  63. data/lib/version.rb +1 -1
  64. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d069eb11240582d89dcf926725415475ace200032f76c8d69cfff1455fc7a5ac
4
- data.tar.gz: d72211728841e2eb31d086fbd47a5eca9196f569aa6d03ad8c59c01bcb266b9d
3
+ metadata.gz: 77e2032efa0ddf9ce5dbeca618a4abeb9784604e1eda780a2a631a5007d69944
4
+ data.tar.gz: c4d8634e037a06d83629ed8a4f779c7820401ed2fc11c3b9e2750e3e1525a03c
5
5
  SHA512:
6
- metadata.gz: 237b980af32dce5743ba0af142bb41e39723306d87d1085f462102d3307f76c89e31f6f2b983d79eb02034f02ea98a81a64e6c3e846b3d8633d4e713f483b5ea
7
- data.tar.gz: f7b252d2fcb5ded4160a77b6dc0891a1a252ef037a374799cf09519341aa9f326f4614f8dabe067845e74080eb0b0fb87f14d439a8ec45f6d35188d69afecf4b
6
+ metadata.gz: 9d40799aaff249470c2ca687b4940dc3e2c83cbb844ad127fd295673facfeaf86d84248345160358c19f34251b7f00a3568196ea80be2942ffb2c43cc2d22353
7
+ data.tar.gz: 0a578b3d96e1526795282ab6202c0aaadce2a4acbc6d0cdb98206a2947bfaf1a87076ea6069025f5171ef6f293c36ddace1f15ba09ce040d871e7028956e595b
data/lib/rudash/at.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Rudash
2
- module At
3
- def at(object, paths)
4
- get_mapper = -> (path) {
5
- self.get(object, path)
6
- }
7
-
8
- self.map(paths, get_mapper)
9
- end
2
+ module At
3
+ def at(object, paths)
4
+ get_mapper = -> (path) {
5
+ self.get(object, path)
6
+ }
7
+
8
+ self.map(paths, get_mapper)
10
9
  end
10
+ end
11
11
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module Capitalize
3
- def capitalize(value)
4
- value.is_a?(String) ? value.capitalize : value.to_s
5
- end
2
+ module Capitalize
3
+ def capitalize(value)
4
+ value.is_a?(String) ? value.capitalize : value.to_s
6
5
  end
6
+ end
7
7
  end
data/lib/rudash/chain.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module Chain
3
- def chain(value)
4
- Rudash::ChainUtils::ChainWrapper.new(value, self)
5
- end
2
+ module Chain
3
+ def chain(value)
4
+ Rudash::ChainUtils::ChainWrapper.new(value, self)
6
5
  end
6
+ end
7
7
  end
@@ -1,8 +1,8 @@
1
1
  module Rudash
2
- module Compact
3
- def compact(array)
4
- return [] if !array.is_a?(Array)
5
- array.compact
6
- end
2
+ module Compact
3
+ def compact(array)
4
+ return [] if !array.is_a?(Array)
5
+ array.compact
7
6
  end
7
+ end
8
8
  end
data/lib/rudash/concat.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Rudash
2
- module Concat
3
- def concat(head, *values)
4
- head_arr = head.is_a?(Array) ? head : [head]
5
- if values.size == 0
6
- return head_arr
7
- else
8
- return head_arr + self.concat(*values)
9
- end
10
- end
2
+ module Concat
3
+ def concat(head, *values)
4
+ head_arr = head.is_a?(Array) ? head : [head]
5
+ if values.size == 0
6
+ return head_arr
7
+ else
8
+ return head_arr + self.concat(*values)
9
+ end
11
10
  end
11
+ end
12
12
  end
data/lib/rudash/curry.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module Curry
3
- def curry(a_proc)
4
- a_proc.is_a?(Proc) ? a_proc.curry : (raise 'Expected a Proc')
5
- end
2
+ module Curry
3
+ def curry(a_proc)
4
+ a_proc.is_a?(Proc) ? a_proc.curry : (raise 'Expected a Proc')
6
5
  end
6
+ end
7
7
  end
@@ -1,14 +1,14 @@
1
1
  module Rudash
2
- module Difference
3
- def difference(*values)
4
- diff_reducer = -> (acc, current) {
5
- return [] if !acc.is_a?(Array)
6
- return acc if !current.is_a?(Array)
7
-
8
- acc - current
9
- }
10
-
11
- self.reduce(values, diff_reducer)
12
- end
2
+ module Difference
3
+ def difference(*values)
4
+ diff_reducer = -> (acc, current) {
5
+ return [] if !acc.is_a?(Array)
6
+ return acc if !current.is_a?(Array)
7
+
8
+ acc - current
9
+ }
10
+
11
+ self.reduce(values, diff_reducer)
13
12
  end
13
+ end
14
14
  end
@@ -1,12 +1,12 @@
1
1
  module Rudash
2
- module DropRight
3
- def drop_right(array, *rest_args)
4
- return [] if !self.is_array?(array)
5
-
6
- n = self.head(rest_args) || 1
7
- return array if n <= 0
8
-
9
- self.take(array, self.size(array) - n)
10
- end
2
+ module DropRight
3
+ def drop_right(array, *rest_args)
4
+ return [] if !self.is_array?(array)
5
+
6
+ n = self.head(rest_args) || 1
7
+ return array if n <= 0
8
+
9
+ self.take(array, self.size(array) - n)
11
10
  end
11
+ end
12
12
  end
data/lib/rudash/each.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Rudash
2
- module Each
3
- def each(collection, *rest_args)
4
- self.map(collection, *rest_args)
5
- collection
6
- end
2
+ module Each
3
+ def each(collection, *rest_args)
4
+ self.map(collection, *rest_args)
5
+ collection
6
+ end
7
7
 
8
- def for_each(*args)
9
- self.each(*args)
10
- end
8
+ def for_each(*args)
9
+ self.each(*args)
11
10
  end
11
+ end
12
12
  end
@@ -1,14 +1,14 @@
1
1
  module Rudash
2
- module EachRight
3
- def each_right(collection, *rest_args)
4
- reversed_collection = Rudash::Utils.force_reverse(collection)
5
-
6
- self.each(reversed_collection, *rest_args)
7
- collection
8
- end
2
+ module EachRight
3
+ def each_right(collection, *rest_args)
4
+ reversed_collection = Rudash::Utils.force_reverse(collection)
5
+
6
+ self.each(reversed_collection, *rest_args)
7
+ collection
8
+ end
9
9
 
10
- def for_each_right(*args)
11
- self.each_right(*args)
12
- end
10
+ def for_each_right(*args)
11
+ self.each_right(*args)
13
12
  end
13
+ end
14
14
  end
data/lib/rudash/eq.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module Eq
3
- def eq?(object, other)
4
- object.equal?(other)
5
- end
2
+ module Eq
3
+ def eq?(object, other)
4
+ object.equal?(other)
6
5
  end
6
+ end
7
7
  end
data/lib/rudash/every.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Rudash
2
- module Every
3
- def every?(array, filter)
4
- filtered_arr = self.filter(array, filter)
5
- filtered_arr.length == array.length
6
- end
2
+ module Every
3
+ def every?(array, filter)
4
+ filtered_arr = self.filter(array, filter)
5
+ filtered_arr.length == array.length
7
6
  end
7
+ end
8
8
  end
data/lib/rudash/filter.rb CHANGED
@@ -1,26 +1,26 @@
1
1
  module Rudash
2
- module Filter
3
- def filter(collection, *rest_args)
4
- predicate_fn = self.head(rest_args) || self.method(:identity)
5
-
6
- if predicate_fn.is_a?(Hash)
7
- slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(predicate_fn)
8
- return self.filter(collection, slice_matcher)
9
- end
10
-
11
- return [] if !Rudash::Utils.is_function?(predicate_fn)
12
-
13
- if collection.is_a?(Array)
14
- return collection.select.with_index { |x, idx|
15
- Rudash::DynamicArgsCount.call(predicate_fn, x, idx)
16
- }
17
- elsif collection.is_a?(Hash)
18
- return collection.select { |k, v|
19
- Rudash::DynamicArgsCount.call(predicate_fn, v, k)
20
- }.values
21
- else
22
- return []
23
- end
24
- end
2
+ module Filter
3
+ def filter(collection, *rest_args)
4
+ predicate_fn = self.head(rest_args) || self.method(:identity)
5
+
6
+ if predicate_fn.is_a?(Hash)
7
+ slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(predicate_fn)
8
+ return self.filter(collection, slice_matcher)
9
+ end
10
+
11
+ return [] if !Rudash::Utils.is_function?(predicate_fn)
12
+
13
+ if collection.is_a?(Array)
14
+ return collection.select.with_index { |x, idx|
15
+ Rudash::DynamicArgsCount.call(predicate_fn, x, idx)
16
+ }
17
+ elsif collection.is_a?(Hash)
18
+ return collection.select { |k, v|
19
+ Rudash::DynamicArgsCount.call(predicate_fn, v, k)
20
+ }.values
21
+ else
22
+ return []
23
+ end
25
24
  end
25
+ end
26
26
  end
data/lib/rudash/find.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Rudash
2
- module Find
3
- def find(collection, *rest_args)
4
- iteratee_fn = self.head(rest_args)
5
- filtered_arr = self.filter(collection, iteratee_fn)
6
-
7
- filtered_arr[0]
8
- end
2
+ module Find
3
+ def find(collection, *rest_args)
4
+ iteratee_fn = self.head(rest_args)
5
+ filtered_arr = self.filter(collection, iteratee_fn)
6
+
7
+ filtered_arr[0]
9
8
  end
9
+ end
10
10
  end
@@ -1,10 +1,10 @@
1
1
  module Rudash
2
- module FindLast
3
- def find_last(collection, *rest_args)
4
- iteratee_fn = self.head(rest_args)
5
- filtered_arr = self.filter(collection, iteratee_fn)
6
-
7
- filtered_arr[filtered_arr.length - 1]
8
- end
2
+ module FindLast
3
+ def find_last(collection, *rest_args)
4
+ iteratee_fn = self.head(rest_args)
5
+ filtered_arr = self.filter(collection, iteratee_fn)
6
+
7
+ filtered_arr[filtered_arr.length - 1]
9
8
  end
9
+ end
10
10
  end
data/lib/rudash/flip.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  module Rudash
2
- module Flip
3
- def flip(a_proc)
4
- raise 'Expected a Proc/Method' if !Rudash::Utils.is_function?(a_proc)
5
-
6
- flipped_proc = -> (*args) {
7
- reveresed_args = args.reverse
8
-
9
- a_proc.(*reveresed_args)
10
- }
11
- end
2
+ module Flip
3
+ def flip(a_proc)
4
+ raise 'Expected a Proc/Method' if !Rudash::Utils.is_function?(a_proc)
5
+
6
+ flipped_proc = -> (*args) {
7
+ reveresed_args = args.reverse
8
+
9
+ a_proc.(*reveresed_args)
10
+ }
12
11
  end
12
+ end
13
13
  end
data/lib/rudash/flow.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  module Rudash
2
- module Flow
3
- def flow(*funs)
4
- flatten_funs = funs.flatten
5
-
6
- flow_proc = -> (*args) {
7
- self.reduce(flatten_funs, -> (acc, fn) {
8
- Rudash::DynamicArgsCount.call(fn, *self.concat(acc))
9
- }, args)
10
- }
11
- end
2
+ module Flow
3
+ def flow(*funs)
4
+ flatten_funs = funs.flatten
5
+
6
+ flow_proc = -> (*args) {
7
+ self.reduce(flatten_funs, -> (acc, fn) {
8
+ Rudash::DynamicArgsCount.call(fn, *self.concat(acc))
9
+ }, args)
10
+ }
11
+ end
12
12
  end
13
- end
13
+ end
@@ -1,9 +1,9 @@
1
1
  module Rudash
2
- module FlowRight
3
- def flow_right(*funs)
4
- flatten_funs = funs.flatten.reverse
5
-
6
- self.flow(flatten_funs)
7
- end
2
+ module FlowRight
3
+ def flow_right(*funs)
4
+ flatten_funs = funs.flatten.reverse
5
+
6
+ self.flow(flatten_funs)
8
7
  end
8
+ end
9
9
  end
data/lib/rudash/get.rb CHANGED
@@ -1,26 +1,26 @@
1
1
  module Rudash
2
- module Get
3
- def get(hash, path, *rest_args)
4
- return nil if !path.is_a?(String) && !path.is_a?(Array)
5
- return nil if !hash.is_a?(Array) && !hash.is_a?(Hash)
6
-
7
- resolved_path = Rudash::PathResolver.resolve(path)
8
-
9
- get_reducer = -> (acc, current) {
10
- return nil if acc.nil?
11
-
12
- if acc.is_a?(Array) && Rudash::Utils.match_number?(current)
13
- acc[current.to_i]
14
- elsif acc.is_a?(Array) && !Rudash::Utils.match_number?(current)
15
- nil
16
- elsif acc.is_a?(Hash)
17
- acc[current.to_sym] || acc[current]
18
- else
19
- nil
20
- end
21
- }
22
-
23
- self.reduce(resolved_path, get_reducer, hash)
2
+ module Get
3
+ def get(hash, path, *rest_args)
4
+ return nil if !path.is_a?(String) && !path.is_a?(Array)
5
+ return nil if !hash.is_a?(Array) && !hash.is_a?(Hash)
6
+
7
+ resolved_path = Rudash::PathResolver.resolve(path)
8
+
9
+ get_reducer = -> (acc, current) {
10
+ return nil if acc.nil?
11
+
12
+ if acc.is_a?(Array) && Rudash::Utils.match_number?(current)
13
+ acc[current.to_i]
14
+ elsif acc.is_a?(Array) && !Rudash::Utils.match_number?(current)
15
+ nil
16
+ elsif acc.is_a?(Hash)
17
+ acc[current.to_sym] || acc[current]
18
+ else
19
+ nil
24
20
  end
21
+ }
22
+
23
+ self.reduce(resolved_path, get_reducer, hash)
25
24
  end
25
+ end
26
26
  end
@@ -1,21 +1,21 @@
1
1
  module Rudash
2
- module GroupBy
3
- def group_by(collection, *rest_args)
4
- iteratee = self.head(rest_args) || self.method(:identity)
5
-
6
- reducer = -> (acc, current) {
7
- key = Rudash::DynamicArgsCount.call(iteratee, current)
8
-
9
- if acc[key]
10
- acc[key] << current
11
- else
12
- acc[key] = [current]
13
- end
14
-
15
- acc
16
- }
17
-
18
- self.reduce(collection, reducer, {})
2
+ module GroupBy
3
+ def group_by(collection, *rest_args)
4
+ iteratee = self.head(rest_args) || self.method(:identity)
5
+
6
+ reducer = -> (acc, current) {
7
+ key = Rudash::DynamicArgsCount.call(iteratee, current)
8
+
9
+ if acc[key]
10
+ acc[key] << current
11
+ else
12
+ acc[key] = [current]
19
13
  end
14
+
15
+ acc
16
+ }
17
+
18
+ self.reduce(collection, reducer, {})
20
19
  end
20
+ end
21
21
  end
data/lib/rudash/head.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Rudash
2
- module Head
3
- def head(array)
4
- return nil if !array.is_a?(Array)
5
- array.first
6
- end
2
+ module Head
3
+ def head(array)
4
+ return nil if !array.is_a?(Array)
5
+ array.first
6
+ end
7
7
 
8
- def first(*args)
9
- self.head(*args)
10
- end
8
+ def first(*args)
9
+ self.head(*args)
11
10
  end
11
+ end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module Identity
3
- def identity(first_arg, *rest_args)
4
- first_arg
5
- end
2
+ module Identity
3
+ def identity(first_arg, *rest_args)
4
+ first_arg
6
5
  end
6
+ end
7
7
  end
@@ -1,9 +1,9 @@
1
1
  module Rudash
2
- module Initial
3
- def initial(array)
4
- return [] if !array.is_a?(Array)
5
- *initial, last = array
6
- initial
7
- end
2
+ module Initial
3
+ def initial(array)
4
+ return [] if !array.is_a?(Array)
5
+ *initial, last = array
6
+ initial
8
7
  end
8
+ end
9
9
  end
@@ -1,13 +1,13 @@
1
1
  module Rudash
2
- module Intersection
3
- def intersection(*values)
4
-
5
- intersection_reducer = -> (acc, current) {
6
- return [] if !current.is_a?(Array) || !acc.is_a?(Array)
7
- acc & current
8
- }
9
-
10
- self.reduce(values, intersection_reducer, values[0])
11
- end
2
+ module Intersection
3
+ def intersection(*values)
4
+
5
+ intersection_reducer = -> (acc, current) {
6
+ return [] if !current.is_a?(Array) || !acc.is_a?(Array)
7
+ acc & current
8
+ }
9
+
10
+ self.reduce(values, intersection_reducer, values[0])
12
11
  end
12
+ end
13
13
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module IsArray
3
- def is_array?(value)
4
- value.is_a?(Array)
5
- end
2
+ module IsArray
3
+ def is_array?(value)
4
+ value.is_a?(Array)
6
5
  end
6
+ end
7
7
  end
@@ -1,12 +1,12 @@
1
1
  module Rudash
2
- module IsEmpty
3
- def is_empty?(value)
4
- case value
5
- when Hash, Array
6
- value.empty?
7
- else
8
- true
9
- end
10
- end
2
+ module IsEmpty
3
+ def is_empty?(value)
4
+ case value
5
+ when Hash, Array
6
+ value.empty?
7
+ else
8
+ true
9
+ end
11
10
  end
11
+ end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module IsEqual
3
- def is_equal?(value, other)
4
- value == other
5
- end
2
+ module IsEqual
3
+ def is_equal?(value, other)
4
+ value == other
6
5
  end
6
+ end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module IsHash
3
- def is_hash?(value)
4
- value.is_a?(Hash)
5
- end
2
+ module IsHash
3
+ def is_hash?(value)
4
+ value.is_a?(Hash)
6
5
  end
6
+ end
7
7
  end
data/lib/rudash/is_nil.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module IsNil
3
- def is_nil?(object)
4
- object.nil?
5
- end
2
+ module IsNil
3
+ def is_nil?(object)
4
+ object.nil?
6
5
  end
6
+ end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module IsNumber
3
- def is_number?(value)
4
- value.is_a?(Numeric)
5
- end
2
+ module IsNumber
3
+ def is_number?(value)
4
+ value.is_a?(Numeric)
6
5
  end
6
+ end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
- module IsString
3
- def is_string?(object)
4
- object.is_a?(String)
5
- end
2
+ module IsString
3
+ def is_string?(object)
4
+ object.is_a?(String)
6
5
  end
6
+ end
7
7
  end