rudash 2.9.0 → 2.9.1

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
2
  SHA256:
3
- metadata.gz: 533e5c283a3565293e86f436ad14c5c31130a6e87ec4a604e2247dc8b33969c4
4
- data.tar.gz: 7d5f63bdfac9d6b7759f99ca35e9be4ea07e0d7280bbc43f559c565fb7769810
3
+ metadata.gz: 82271921675a8d420c4e1dd198c0e07f6438a323040ac28f6cb07042e776ad3c
4
+ data.tar.gz: 66901b07176af3319fce0a930752d03e1d761652cccc47a7f1d7be300af45676
5
5
  SHA512:
6
- metadata.gz: 453931f3c25a2d5b7a2d6e86a71eeed859c1556cfd8006ad89e7d1876c0d0b0f8c1a90b62beacbe1ae98227efee6cca9a0149eb9a527ce6045afd1602d4d0a73
7
- data.tar.gz: d86479387726933384808b41a435176eb271ec17fbab369e58ec6d71d9c8256a1986804a0271637d29b4336baf1da31ec0cd6051e1d4b037c635807b18a5809f
6
+ metadata.gz: 4087dbb48f61d30663fe2f25b18866bd2b1dcd8c1878692243330fe0cdcf6708dabdddd7ab07d892f221d7084d51d78f68076a92e5450d8ba98ae7067e477050
7
+ data.tar.gz: d8c6597e919c2e3d9a5e3e148adbc5a2b1bcbef14cac0113f5a391e05a545d1dbd188f0b15176ee4ead8acd42e084ca03964bf3983b283925ec96b4601ac91ea
data/lib/rudash.rb CHANGED
@@ -20,7 +20,6 @@ require_relative './rudash/is_array.rb'
20
20
  require_relative './rudash/is_equal.rb'
21
21
  require_relative './rudash/is_hash.rb'
22
22
  require_relative './rudash/is_empty.rb'
23
- require_relative './rudash/is_proc.rb'
24
23
  require_relative './rudash/reverse.rb'
25
24
  require_relative './rudash/curry.rb'
26
25
  require_relative './rudash/is_number.rb'
@@ -72,7 +71,6 @@ class R_
72
71
  extend Rudash::IsEqual
73
72
  extend Rudash::IsHash
74
73
  extend Rudash::IsEmpty
75
- extend Rudash::IsProc
76
74
  extend Rudash::Reverse
77
75
  extend Rudash::Curry
78
76
  extend Rudash::IsNumber
data/lib/rudash/filter.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require_relative '../utils/index.rb'
1
2
  require_relative '../utils/subset_deep_match.rb'
2
3
 
3
4
  module Rudash
@@ -9,6 +10,8 @@ module Rudash
9
10
  slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(filter)
10
11
  return self.filter(collection, slice_matcher)
11
12
  end
13
+
14
+ return [] if !Rudash::Utils.is_function?(filter)
12
15
 
13
16
  if collection.is_a?(Array)
14
17
  begin
data/lib/rudash/flip.rb CHANGED
@@ -1,6 +1,10 @@
1
+ require_relative '../utils/index.rb'
2
+
1
3
  module Rudash
2
4
  module Flip
3
5
  def flip(a_proc)
6
+ raise 'Expected a Proc/Method' if !Rudash::Utils.is_function?(a_proc)
7
+
4
8
  flipped_proc = -> (*args) {
5
9
  reveresed_args = args.reverse
6
10
 
data/lib/rudash/map.rb CHANGED
@@ -1,9 +1,12 @@
1
+ require_relative '../utils/index.rb'
2
+
1
3
  module Rudash
2
4
  module Map
3
5
  def map(collection, *rest_args)
4
6
  mapper_proc = self.head(rest_args) || self.method(:identity)
5
-
6
7
  col = collection.is_a?(String) ? collection.split('') : collection
8
+
9
+ return self.map(collection, -> () { nil }) if !Rudash::Utils.is_function?(mapper_proc)
7
10
 
8
11
  if col.is_a?(Array)
9
12
  begin
data/lib/rudash/negate.rb CHANGED
@@ -1,14 +1,13 @@
1
+ require_relative '../utils/index.rb'
2
+
1
3
  module Rudash
2
4
  module Negate
3
5
  def negate(a_proc)
4
- case a_proc
5
- when Proc
6
- negate_proc = -> (*args) {
7
- !a_proc.(*args)
8
- }
9
- else
10
- raise 'Expected a Proc'
11
- end
6
+ raise 'Expected a Proc/Method' if !Rudash::Utils.is_function?(a_proc)
7
+
8
+ negate_proc = -> (*args) {
9
+ !a_proc.(*args)
10
+ }
12
11
  end
13
12
  end
14
13
  end
data/lib/rudash/reduce.rb CHANGED
@@ -1,10 +1,13 @@
1
+ require_relative '../utils/index.rb'
2
+
1
3
  module Rudash
2
4
  module Reduce
3
5
  def reduce(collection, *rest_args)
4
6
  reducer = rest_args[0]
5
7
  initial_state = rest_args[1]
6
-
7
8
  col = collection.is_a?(String) ? collection.split('') : collection
9
+
10
+ return self.reduce(collection, -> (acc, current) { nil }) if !Rudash::Utils.is_function?(reducer)
8
11
 
9
12
  case rest_args.size
10
13
  when 1
data/lib/rudash/reject.rb CHANGED
@@ -1,14 +1,15 @@
1
+ require_relative '../utils/index.rb'
1
2
  require_relative '../utils/subset_deep_match.rb'
2
3
 
3
4
  module Rudash
4
5
  module Reject
5
6
  def reject(collection, *rest_args)
6
- filter = self.head(rest_args) || self.method(:identity).to_proc
7
+ filter = self.head(rest_args) || self.method(:identity)
7
8
 
8
9
  if filter.is_a?(Hash)
9
10
  slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(filter)
10
11
  return self.filter(collection, self.negate(slice_matcher))
11
- elsif filter.is_a?(Proc)
12
+ elsif Rudash::Utils.is_function?(filter)
12
13
  return self.filter(collection, self.negate(filter))
13
14
  else
14
15
  return []
data/lib/rudash/update.rb CHANGED
@@ -1,7 +1,11 @@
1
+ require_relative '../utils/index.rb'
2
+
1
3
  module Rudash
2
4
  module Update
3
5
  def update(object, path, *rest_args)
4
6
  updater = self.head(rest_args) || self.method(:identity)
7
+ return object if !Rudash::Utils.is_function?(updater)
8
+
5
9
  current_value = self.get(object, path)
6
10
  self.set(object, path, updater.(current_value))
7
11
  object
data/lib/utils/index.rb CHANGED
@@ -6,6 +6,10 @@ module Rudash
6
6
  return false if !str.is_a?(String)
7
7
  str.match(/^(\d)+$/)
8
8
  end
9
+
10
+ def self.is_function?(func)
11
+ func.is_a?(Proc) || func.is_a?(Method)
12
+ end
9
13
 
10
14
  def self.force_reverse(collection)
11
15
  case collection
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.9.0
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Islam Attrash
@@ -42,7 +42,6 @@ files:
42
42
  - lib/rudash/is_hash.rb
43
43
  - lib/rudash/is_nil.rb
44
44
  - lib/rudash/is_number.rb
45
- - lib/rudash/is_proc.rb
46
45
  - lib/rudash/is_string.rb
47
46
  - lib/rudash/join.rb
48
47
  - lib/rudash/keys.rb
@@ -1,7 +0,0 @@
1
- module Rudash
2
- module IsProc
3
- def is_proc?(value)
4
- value.is_a?(Proc)
5
- end
6
- end
7
- end