rudash 2.17.4 → 3.0.0

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: 3d799e40ff80455b2ed477fc110aa72a0cac0ebf1f3523e0bcb9faebabff0e93
4
- data.tar.gz: 7e3d4c6be34feb99a7791bce6482a685d9b9944f4b59b0d21f6c8af9ba376d54
3
+ metadata.gz: 010e99090c5a7822aed08f891f2c1619f0fa7a4375236138cc1964085e56e4c3
4
+ data.tar.gz: 285bb203659eff8822da94e78e881f0288a5fb64545c8b549208391e085eae33
5
5
  SHA512:
6
- metadata.gz: 2b58b76b34470accda8d425d539d1a90414df30fd58bd2f226b152ea73afa92cbd2116eb010b1434d7026a7f57c98f7155e9bfff98ae5046ae1d7e8854751cc7
7
- data.tar.gz: b4eb8d6c1577c3ed0243066f16434e35d111aa74c00abbfb22a15ef1a1611dcb587f82f1fca571dfb3581406fc24184017c51aeb7e19d96abf33ea73bc1a00df
6
+ metadata.gz: 6eb6463f8b89b738c486aa04f4be34388765b2a17a0732a520eb49698d1575380e0484d7886772d5ea229348fef03bfe614ea1de1749db646c4ac4bb7b478460
7
+ data.tar.gz: cb38153995314e82750e09245286e5c8fdc38b4b2d16fb28f63677f6730160db2a1c908985895683824cc850fb8aa6b3389a8544d7b65295cd186fb112d23ea1
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsArray
3
- def is_array?(value)
3
+ def array?(value)
4
4
  value.is_a?(Array)
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
2
  module DropRight
3
3
  def drop_right(array, *rest_args)
4
- return [] unless self.is_array?(array)
4
+ return [] unless self.array?(array)
5
5
 
6
6
  n = self.head(rest_args) || 1
7
7
  return array if n <= 0
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsEmpty
3
- def is_empty?(value)
3
+ def empty?(value)
4
4
  case value
5
5
  when Hash, Array
6
6
  value.empty?
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsEqual
3
- def is_equal?(value, other)
3
+ def equal?(value, other)
4
4
  value == other
5
5
  end
6
6
  end
data/lib/rudash/filter.rb CHANGED
@@ -8,7 +8,7 @@ module Rudash
8
8
  return self.filter(collection, slice_matcher)
9
9
  end
10
10
 
11
- return [] unless Rudash::Utils.is_function?(predicate_fn)
11
+ return [] unless Rudash::Utils.function?(predicate_fn)
12
12
 
13
13
  if collection.is_a?(Array)
14
14
  return collection.select.with_index do |x, idx|
data/lib/rudash/flip.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Rudash
2
2
  module Flip
3
3
  def flip(a_proc)
4
- raise 'Expected a Proc/Method' unless Rudash::Utils.is_function?(a_proc)
4
+ raise 'Expected a Proc/Method' unless Rudash::Utils.function?(a_proc)
5
5
 
6
6
  ->(*args) {
7
7
  reveresed_args = args.reverse
8
8
 
9
- a_proc.(*reveresed_args)
9
+ a_proc.call(*reveresed_args)
10
10
  }
11
11
  end
12
12
  end
data/lib/rudash/get.rb CHANGED
@@ -16,7 +16,7 @@ module Rudash
16
16
  elsif acc.is_a?(Hash)
17
17
  acc[current.to_sym] || acc[current]
18
18
  else
19
- nil
19
+ return nil
20
20
  end
21
21
  }
22
22
 
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsHash
3
- def is_hash?(value)
3
+ def hash?(value)
4
4
  value.is_a?(Hash)
5
5
  end
6
6
  end
data/lib/rudash/map.rb CHANGED
@@ -4,12 +4,12 @@ module Rudash
4
4
  iteratee_fn = self.head(rest_args) || self.method(:identity)
5
5
  col = collection.is_a?(String) ? collection.split('') : collection
6
6
 
7
- return self.map(collection, ->() { nil }) unless Rudash::Utils.is_function?(iteratee_fn)
7
+ return self.map(collection, -> { nil }) unless Rudash::Utils.function?(iteratee_fn)
8
8
 
9
9
  if col.is_a?(Array)
10
- return col.map.with_index { |value, index|
10
+ return col.map.with_index do |value, index|
11
11
  Rudash::DynamicArgsCount.call(iteratee_fn, value, index)
12
- }
12
+ end
13
13
  elsif col.is_a?(Hash)
14
14
  return col.map do |k, v|
15
15
  Rudash::DynamicArgsCount.call(iteratee_fn, v, k)
data/lib/rudash/negate.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
2
  module Negate
3
3
  def negate(a_proc)
4
- raise 'Expected a Proc/Method' unless Rudash::Utils.is_function?(a_proc)
4
+ raise 'Expected a Proc/Method' unless Rudash::Utils.function?(a_proc)
5
5
 
6
6
  ->(*args) { !a_proc.call(*args) }
7
7
  end
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsNil
3
- def is_nil?(object)
3
+ def nil?(object)
4
4
  object.nil?
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsNumber
3
- def is_number?(value)
3
+ def number?(value)
4
4
  value.is_a?(Numeric)
5
5
  end
6
6
  end
data/lib/rudash/reduce.rb CHANGED
@@ -5,7 +5,7 @@ module Rudash
5
5
  initial_state = rest_args[1]
6
6
  col = collection.is_a?(String) ? collection.split('') : collection
7
7
 
8
- return self.reduce(collection, -> () { nil }) unless Rudash::Utils.is_function?(reducer)
8
+ return self.reduce(collection, -> { nil }) unless Rudash::Utils.function?(reducer)
9
9
 
10
10
  case rest_args.size
11
11
  when 1
@@ -17,13 +17,13 @@ module Rudash
17
17
  end
18
18
  end
19
19
  when 2
20
- return col.reduce(initial_state) { |acc, current|
20
+ return col.reduce(initial_state) do |acc, current|
21
21
  if col.is_a?(Hash)
22
22
  Rudash::DynamicArgsCount.call(reducer, acc, current[1], current[0])
23
23
  else
24
24
  Rudash::DynamicArgsCount.call(reducer, acc, current)
25
25
  end
26
- }
26
+ end
27
27
  else
28
28
  return nil
29
29
  end
data/lib/rudash/reject.rb CHANGED
@@ -6,7 +6,7 @@ module Rudash
6
6
  if filter.is_a?(Hash)
7
7
  slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.call(filter)
8
8
  return self.filter(collection, self.negate(slice_matcher))
9
- elsif Rudash::Utils.is_function?(filter)
9
+ elsif Rudash::Utils.function?(filter)
10
10
  return self.filter(collection, self.negate(filter))
11
11
  else
12
12
  return []
data/lib/rudash/size.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
2
  module Size
3
3
  def size(something)
4
- return 0 if self.is_nil?(something)
4
+ return 0 if self.nil?(something)
5
5
 
6
6
  something.size
7
7
  end
@@ -1,6 +1,6 @@
1
1
  module Rudash
2
2
  module IsString
3
- def is_string?(object)
3
+ def string?(object)
4
4
  object.is_a?(String)
5
5
  end
6
6
  end
data/lib/rudash/take.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rudash
2
2
  module Take
3
3
  def take(array, *rest_args)
4
- return [] unless self.is_array?(array)
4
+ return [] unless self.array?(array)
5
5
 
6
6
  count = self.head(rest_args) || 1
7
7
 
data/lib/rudash/union.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Rudash
2
2
  module Union
3
3
  def union(*values)
4
-
5
4
  union_reducer = ->(acc, current) {
6
5
  return acc if !current.is_a?(Array) || !acc.is_a?(Array)
7
6
 
data/lib/rudash/update.rb CHANGED
@@ -2,10 +2,14 @@ module Rudash
2
2
  module Update
3
3
  def update(object, path, *rest_args)
4
4
  updater_fn = self.head(rest_args) || self.method(:identity)
5
- return object unless Rudash::Utils.is_function?(updater_fn)
5
+ return object unless Rudash::Utils.function?(updater_fn)
6
6
 
7
7
  current_value = self.get(object, path)
8
- self.set(object, path, Rudash::DynamicArgsCount.call(updater_fn, current_value))
8
+ self.set(
9
+ object,
10
+ path,
11
+ Rudash::DynamicArgsCount.call(updater_fn, current_value)
12
+ )
9
13
  object
10
14
  end
11
15
  end
data/lib/rudash.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require_relative './rudash/map.rb'
2
- require_relative './rudash/is_nil.rb'
2
+ require_relative './rudash/nil.rb'
3
3
  require_relative './rudash/filter.rb'
4
4
  require_relative './rudash/some.rb'
5
5
  require_relative './rudash/every.rb'
@@ -16,18 +16,18 @@ require_relative './rudash/size.rb'
16
16
  require_relative './rudash/flip.rb'
17
17
  require_relative './rudash/identity.rb'
18
18
  require_relative './rudash/get.rb'
19
- require_relative './rudash/is_array.rb'
20
- require_relative './rudash/is_equal.rb'
21
- require_relative './rudash/is_hash.rb'
22
- require_relative './rudash/is_empty.rb'
19
+ require_relative './rudash/array.rb'
20
+ require_relative './rudash/equal.rb'
21
+ require_relative './rudash/hash.rb'
22
+ require_relative './rudash/empty.rb'
23
23
  require_relative './rudash/reverse.rb'
24
24
  require_relative './rudash/curry.rb'
25
- require_relative './rudash/is_number.rb'
25
+ require_relative './rudash/number.rb'
26
26
  require_relative './rudash/keys.rb'
27
27
  require_relative './rudash/each.rb'
28
28
  require_relative './rudash/uniq.rb'
29
29
  require_relative './rudash/difference.rb'
30
- require_relative './rudash/is_string.rb'
30
+ require_relative './rudash/string.rb'
31
31
  require_relative './rudash/eq.rb'
32
32
  require_relative './rudash/each_right.rb'
33
33
  require_relative './rudash/at.rb'
@@ -64,6 +64,8 @@ require_relative './utils/chain_wrapper.rb'
64
64
  # This is the exposed Gem class that contains all Rudash methods.
65
65
  # New methods can use already implemented methods by refering to "self"
66
66
  # in the method if and only if the method get extended into the R_ class.
67
+
68
+ # rubocop:disable Naming/ClassAndModuleCamelCase
67
69
  class R_
68
70
  extend Rudash::Map
69
71
  extend Rudash::IsNil
@@ -120,3 +122,5 @@ class R_
120
122
  extend Rudash::FlowRight
121
123
  extend Rudash::Unset
122
124
  end
125
+
126
+ # rubocop:enable Naming/ClassAndModuleCamelCase
@@ -3,16 +3,16 @@ module Rudash
3
3
  class ChainWrapper
4
4
  attr_reader :value
5
5
 
6
- def initialize(value, r_)
6
+ def initialize(value, ru_)
7
7
  @value = value
8
- @r_ = r_
8
+ @ru_ = ru_
9
9
  end
10
10
 
11
11
  def method_missing(method_name, *args, &_block)
12
- result = @r_.public_send(method_name, @value, *args)
13
- self.class.new(result, @r_)
12
+ result = @ru_.public_send(method_name, @value, *args)
13
+ self.class.new(result, @ru_)
14
14
  rescue NameError
15
- raise NameError.new("\"#{method_name}\" doesn't exist in Rudash")
15
+ raise NameError, "\"#{method_name}\" doesn't exist in Rudash"
16
16
  end
17
17
  end
18
18
  end
@@ -1,16 +1,17 @@
1
- # This module was written in order to give the predicate functions for R_.filter, R_.map, R_.each, etc..
2
- # to be called with any dynamic arguments as it can. What differante JavaScript from Ruby is that once you configured a function
3
- # with a specific set of arguments then you must call it with that set or else you will get an exception.
4
- # That is so useful for predicate functions that developer define out of the library scope. We send all the arguments
5
- # to the developer defined Proc and if it's failed because of ArgumentError we call it recursively with less argument until success.
1
+ # This module was written in order to give the predicate functions for R_.filter, R_.map, R_.each.
2
+ # to be called with any dynamic arguments as it can. What differante JavaScript from Ruby is that
3
+ # once you configured a function with a specific set of arguments then you must call it with that
4
+ # set or else you will get an exception.
5
+ # That is so useful for predicate functions that developer define out of the library scope.
6
+ # We send all the arguments to the developer defined Proc and if it's failed
7
+ # because of ArgumentError we call it recursively with less argument until success.
6
8
 
7
9
  module Rudash
8
10
  module DynamicArgsCount
9
11
  def self.call(func, *args)
10
12
  func.call(*args)
11
-
12
13
  rescue ArgumentError
13
- raise ArgumentError.new('Argument Error') if args.size.zero?
14
+ raise ArgumentError, 'Argument Error' if args.size.zero?
14
15
 
15
16
  *initial, _last = args
16
17
  self.call(func, *initial)
data/lib/utils/index.rb CHANGED
@@ -8,7 +8,7 @@ module Rudash
8
8
  str.match(/^(\d)+$/)
9
9
  end
10
10
 
11
- def self.is_function?(func)
11
+ def self.function?(func)
12
12
  func.is_a?(Proc) || func.is_a?(Method)
13
13
  end
14
14
 
@@ -3,27 +3,24 @@ require_relative './index.rb'
3
3
 
4
4
  # This module will create the nested path when using R_.set on not existing paths
5
5
  # If we've a hash as { a: 1 } and we run R_.set(hash, 'a.b.c.d', 5) then we want to create the whole
6
- # path ['a', 'b', 'c', 'd'] as embedded hashes. If we have some string that matches a number then we create an array.
6
+ # path ['a', 'b', 'c', 'd'] as embedded hashes.
7
+ # If we have some string that matches a number then we create an array.
7
8
 
8
9
  module Rudash
9
10
  module NestedPathCreator
10
11
  def self.create_path_if_not_exist(object, resolved_path)
11
12
  path = R_.head(resolved_path)
12
- return nil if !resolved_path.is_a?(Array) || R_.is_nil?(path)
13
+ return nil if !resolved_path.is_a?(Array) || R_.nil?(path)
13
14
 
14
15
  path_key = Utils.match_number?(path) ? path.to_i : path.to_sym
15
16
  rest_paths = R_.tail(resolved_path)
16
17
  next_path = R_.head(rest_paths)
17
18
  value = R_.get(object, path)
18
19
 
19
- if R_.is_nil?(value) || (!value.is_a?(Hash) && !value.is_a?(Array))
20
+ if R_.nil?(value) || (!value.is_a?(Hash) && !value.is_a?(Array))
20
21
  # If the next path item is numeric (index)
21
22
  # then we want to create an array otherwise we create a hash
22
- if next_path && Utils.match_number?(next_path)
23
- object[path_key] = []
24
- else
25
- object[path_key] = {}
26
- end
23
+ object[path_key] = next_path && Utils.match_number?(next_path) ? [] : {}
27
24
  end
28
25
 
29
26
  # Do the same recursively for next path
@@ -2,17 +2,16 @@ require_relative '../rudash'
2
2
 
3
3
  # This module have the logic of resolving the paths for R_.get, R_.set and R_.update.
4
4
  # The resolve method will transform the path 'a.b.c.d[0]' to ['a', 'b', 'c', 'd', '0'].
5
- # The mentioned functions above can get the path in either way but we want to normilize the string path
6
- # to the array shape in order to make the logic related only to one data structure.
5
+ # The mentioned functions above can get the path in either way
6
+ # but we want to normilize the string path to the array shape in order to
7
+ # make the logic related only to one data structure.
7
8
 
8
9
  module Rudash
9
10
  module PathResolver
10
11
  def self.resolve(path)
11
12
  normalized_path = path
12
13
 
13
- if normalized_path.is_a?(Array)
14
- normalized_path = normalized_path.join('.')
15
- end
14
+ normalized_path = normalized_path.join('.') if normalized_path.is_a?(Array)
16
15
 
17
16
  filter_not_empty = ->(value) {
18
17
  value != ''
@@ -1,7 +1,7 @@
1
1
  require_relative '../rudash'
2
2
 
3
3
  # This module was written to supply complex subset deep hash and array matching
4
- # in order to give R_.filter, R_.some?, R_.every? and R_.find the ability to deep match with complex hash queries.
4
+ # in order to give filter, some?, every? and find the ability to deep match with complex hash query.
5
5
  # See test_filter_hashes_by_deep_hash (test/filter.rb)
6
6
 
7
7
  module Rudash
@@ -14,9 +14,9 @@ module Rudash
14
14
  # check if every "slice" items exist somehow in the collection
15
15
  # without any order consideration.
16
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?.call(sliceVal, collectionVal)
17
+ return R_.every?(slice, ->(slice_val) {
18
+ R_.some?(collection, ->(collection_val) {
19
+ self.subset_deep_match?.call(slice_val, collection_val)
20
20
  })
21
21
  })
22
22
  end
@@ -39,7 +39,7 @@ module Rudash
39
39
  # It's the same hack for JavaScript forEach function.
40
40
  raise if match == false
41
41
  })
42
- rescue
42
+ rescue StandardError
43
43
  return false
44
44
  end
45
45
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rudash
2
- VERSION = '2.17.4'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  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.17.4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Islam Attrash
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/rudash.rb
20
+ - lib/rudash/array.rb
20
21
  - lib/rudash/at.rb
21
22
  - lib/rudash/capitalize.rb
22
23
  - lib/rudash/chain.rb
@@ -27,7 +28,9 @@ files:
27
28
  - lib/rudash/drop_right.rb
28
29
  - lib/rudash/each.rb
29
30
  - lib/rudash/each_right.rb
31
+ - lib/rudash/empty.rb
30
32
  - lib/rudash/eq.rb
33
+ - lib/rudash/equal.rb
31
34
  - lib/rudash/every.rb
32
35
  - lib/rudash/filter.rb
33
36
  - lib/rudash/find.rb
@@ -37,22 +40,18 @@ files:
37
40
  - lib/rudash/flow_right.rb
38
41
  - lib/rudash/get.rb
39
42
  - lib/rudash/group_by.rb
43
+ - lib/rudash/hash.rb
40
44
  - lib/rudash/head.rb
41
45
  - lib/rudash/identity.rb
42
46
  - lib/rudash/initial.rb
43
47
  - lib/rudash/intersection.rb
44
- - lib/rudash/is_array.rb
45
- - lib/rudash/is_empty.rb
46
- - lib/rudash/is_equal.rb
47
- - lib/rudash/is_hash.rb
48
- - lib/rudash/is_nil.rb
49
- - lib/rudash/is_number.rb
50
- - lib/rudash/is_string.rb
51
48
  - lib/rudash/join.rb
52
49
  - lib/rudash/keys.rb
53
50
  - lib/rudash/last.rb
54
51
  - lib/rudash/map.rb
55
52
  - lib/rudash/negate.rb
53
+ - lib/rudash/nil.rb
54
+ - lib/rudash/number.rb
56
55
  - lib/rudash/pick.rb
57
56
  - lib/rudash/range.rb
58
57
  - lib/rudash/reduce.rb
@@ -64,6 +63,7 @@ files:
64
63
  - lib/rudash/size.rb
65
64
  - lib/rudash/slice.rb
66
65
  - lib/rudash/some.rb
66
+ - lib/rudash/string.rb
67
67
  - lib/rudash/tail.rb
68
68
  - lib/rudash/take.rb
69
69
  - lib/rudash/union.rb