lite-ruby 1.1.15 → 1.3.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
2
  SHA256:
3
- metadata.gz: 3a427f3ee463a045ec4b95c52928b69777b2aa07ae3bd23eaf2835fdcc5abeed
4
- data.tar.gz: 436af138b20c6f1ee2f95ad8df362ecbf6a1299db8cb8bb88118ff7bdc1cc01c
3
+ metadata.gz: 8e3035bce45906f90af5be5db4a0caca9581e73225b46c1639ef98df7ac431ef
4
+ data.tar.gz: 566859827bee72df021c49499b5c4f8c48c880633057a64de94ae491bfdec94f
5
5
  SHA512:
6
- metadata.gz: '030648c74db1997e17bdb0ced23396f0b25c962147d94f91988c3d5a7b64d500c57c8e6b8b3350c455bddf0d95e1b216cb137d27bd6418a5813d51399fdb097f'
7
- data.tar.gz: 982b7a068449a50d1309c49b37725e6ba5ac6718aaa3b87b11fdbe48f5582a1b1d9754bddbc9afe996befadbd43a3f00551bc90cd414a8a95ba682bfdc40cc34
6
+ metadata.gz: 6039e7334d7eace9f2cc0537c8d3b2fe6da1f8e2ec296d445acf0bb2fcae62a9c69b16ea002cffdd75a09178e6b0671f3075045b952493135fae184a27d91054
7
+ data.tar.gz: a9aa682a454cbd7084e74533f7aebdfed02c27fc321e6c6650d872f695d74222d7d7246cd647d1f8b57abe18b14eea6da365e5225fd5396798774e195a5898cc
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ require:
3
3
  - rubocop-rake
4
4
  - rubocop-rspec
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.0
7
7
  NewCops: enable
8
8
  DisplayCopNames: true
9
9
  DisplayStyleGuide: true
data/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.2] - 2021-07-20
10
+ ### Changed
11
+ - Argument passing for try and send methods
12
+
13
+ ## [1.3.1] - 2021-07-20
14
+ ### Removed
15
+ - Struct `[]` and `[]=` existing methods
16
+
17
+ ## [1.3.0] - 2021-07-19
18
+ ### Added
19
+ - Added Ruby 3.0 support
20
+
21
+ ## [1.2.0] - 2021-07-09
22
+ ### Removed
23
+ - OpenStruct block initialization due to unreliability
24
+
9
25
  ## [1.1.15] - 2021-07-05
10
26
  ### Changed
11
27
  - Added more OpenStruct backwards compatibility
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.1.15)
4
+ lite-ruby (1.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,7 +50,7 @@ GEM
50
50
  mini_portile2 (~> 2.5.0)
51
51
  racc (~> 1.4)
52
52
  parallel (1.20.1)
53
- parser (3.0.1.1)
53
+ parser (3.0.2.0)
54
54
  ast (~> 2.4.1)
55
55
  racc (1.5.2)
56
56
  rack (2.2.3)
@@ -68,7 +68,7 @@ GEM
68
68
  rake (>= 0.13)
69
69
  thor (~> 1.0)
70
70
  rainbow (3.0.0)
71
- rake (13.0.3)
71
+ rake (13.0.6)
72
72
  regexp_parser (2.1.1)
73
73
  rexml (3.2.5)
74
74
  rspec (3.10.0)
@@ -84,7 +84,7 @@ GEM
84
84
  diff-lcs (>= 1.2.0, < 2.0)
85
85
  rspec-support (~> 3.10.0)
86
86
  rspec-support (3.10.2)
87
- rubocop (1.18.2)
87
+ rubocop (1.18.3)
88
88
  parallel (~> 1.10)
89
89
  parser (>= 3.0.0.0)
90
90
  rainbow (>= 2.2.2, < 4.0)
@@ -93,9 +93,9 @@ GEM
93
93
  rubocop-ast (>= 1.7.0, < 2.0)
94
94
  ruby-progressbar (~> 1.7)
95
95
  unicode-display_width (>= 1.4.0, < 3.0)
96
- rubocop-ast (1.7.0)
96
+ rubocop-ast (1.8.0)
97
97
  parser (>= 3.0.1.1)
98
- rubocop-performance (1.11.3)
98
+ rubocop-performance (1.11.4)
99
99
  rubocop (>= 1.7.0, < 2.0)
100
100
  rubocop-ast (>= 0.4.0)
101
101
  rubocop-rake (0.6.0)
@@ -129,4 +129,4 @@ DEPENDENCIES
129
129
  rubocop-rspec
130
130
 
131
131
  BUNDLED WITH
132
- 2.2.19
132
+ 2.2.24
data/docs/OPEN_STRUCT.md CHANGED
@@ -1,14 +1,5 @@
1
1
  # OpenStruct
2
2
 
3
- `Initialize`
4
- Allows the initialization of an OpenStruct with a setter block.
5
-
6
- ```ruby
7
- OpenStruct.new(name: 'bob', age: 60) do |o|
8
- o.gender = :M
9
- end
10
- ```
11
-
12
3
  `attributes`
13
4
  ------
14
5
  Returns the key values as a hash of the assigned struct.
data/docs/STRUCT.md CHANGED
@@ -1,30 +1,5 @@
1
1
  # Struct
2
2
 
3
- `[]`
4
- ------
5
- Access a value in the Struct by key, like a Hash.
6
-
7
- ```ruby
8
- person = Struct.new(:name, :age)
9
- person.new('bob', 60)
10
-
11
- person['name'] #=> 'bob'
12
- person['fake'] #=> nil
13
- ```
14
-
15
- `[]=`
16
- ------
17
- Store a value in the Struct by key, like a Hash.
18
-
19
- ```ruby
20
- person = Struct.new(:name, :age)
21
- person.new('bob', 60)
22
-
23
- person['name'] = 'tim'
24
-
25
- person['name'] #=> 'tim'
26
- ```
27
-
28
3
  `attributes`
29
4
  ------
30
5
  Returns the key values of the assigned struct.
@@ -10,7 +10,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
10
10
  1 t true y yes on
11
11
  ].freeze
12
12
 
13
- # NOTE: There is a class between the PG gem and the `array?` method.
13
+ # NOTE: There is a clash between the PG gem and the `array?` method.
14
14
  # We only need to skip this on migrations since that action
15
15
  # happens on a seperate runtime.
16
16
  unless defined?(PG) && ARGV.first.to_s.start_with?('db:')
@@ -55,8 +55,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
55
55
  end
56
56
 
57
57
  # rubocop:disable Naming/PredicateName
58
- def is_any?(*objs)
59
- objs.any? { |obj| is_a?(obj) }
58
+ def is_any?(*objects)
59
+ objects.any? { |obj| is_a?(obj) }
60
60
  end
61
61
  # rubocop:enable Naming/PredicateName
62
62
 
@@ -80,38 +80,38 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
80
80
  is_a?(Range)
81
81
  end
82
82
 
83
- def safe_call(*keys)
84
- try_call(*keys) || self
83
+ def safe_call(...)
84
+ try_call(...) || self
85
85
  end
86
86
 
87
- def safe_send(*keys)
88
- try_send(*keys) || self
87
+ def safe_send(...)
88
+ try_send(...) || self
89
89
  end
90
90
 
91
- def safe_try(*obj, &block)
92
- try(*obj, &block) || self
91
+ def safe_try(...)
92
+ try(...) || self
93
93
  end
94
94
 
95
95
  def salvage(placeholder = '---')
96
96
  blank? ? placeholder : self
97
97
  end
98
98
 
99
- def salvage_try(*obj, placeholder: '---', &block)
100
- try(*obj, &block).salvage(placeholder)
99
+ def salvage_try(method_name = nil, *args, placeholder: '---', &block)
100
+ try(method_name, *args, &block).salvage(placeholder)
101
101
  end
102
102
 
103
- def send_chain(*keys)
104
- Array(keys).inject(self) { |obj, key| obj.send(*key) }
103
+ def send_chain(*args)
104
+ Array(args).inject(self) { |obj, argz| obj.send(*argz) }
105
105
  end
106
106
 
107
- def send_chain_if(*keys)
108
- Array(keys).inject(self) { |obj, key| obj.send_if(*key) }
107
+ def send_chain_if(*args)
108
+ Array(args).inject(self) { |obj, argz| obj.send_if(*argz) }
109
109
  end
110
110
 
111
- def send_if(key, *args)
111
+ def send_if(key, *args, **kwargs, &block)
112
112
  return self unless respond_to?(key)
113
113
 
114
- send(key, *args)
114
+ send(key, *args, **kwargs, &block)
115
115
  end
116
116
 
117
117
  def set?
@@ -151,14 +151,14 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
151
151
  TRUE_VALUES.include?(to_s.downcase)
152
152
  end
153
153
 
154
- def try_call(*keys)
154
+ def try_call(...)
155
155
  return unless respond_to?(:call)
156
156
 
157
- keys.blank? ? call : call(*keys)
157
+ call(...)
158
158
  end
159
159
 
160
- def try_send(*keys)
161
- send(*keys)
160
+ def try_send(...)
161
+ send(...)
162
162
  rescue StandardError
163
163
  nil
164
164
  end
@@ -5,27 +5,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
5
5
 
6
6
  class OpenStruct
7
7
 
8
- def initialize(hash = nil, &block)
9
- @table = if block && block.arity == 2
10
- Hash.new(&block)
11
- else
12
- {}
13
- end
14
-
15
- hash&.each do |key, val|
16
- @table[key.to_sym] = val
17
- new_ostruct_member!(key)
18
- end
19
-
20
- yield self if block && block.arity == 1
21
- end
22
-
23
8
  def attributes
24
9
  @table
25
10
  end
26
11
 
27
12
  def replace(args)
28
- args.each { |key, val| send("#{key}=", val) }
13
+ args.each { |key, val| self[key] = val }
29
14
  end
30
15
 
31
16
  def to_hash(table: true)
@@ -41,38 +26,5 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
41
26
  alias as_json to_json
42
27
  alias to_h to_hash
43
28
 
44
- private
45
-
46
- # rubocop:disable Metrics/MethodLength, Naming/PredicateName
47
- def is_method_protected!(name)
48
- return false unless respond_to?(name, true)
49
- return true if name.match?(/!$/)
50
-
51
- method = 'method'
52
- method << '!' if respond_to?(:method!)
53
- owner = send(method, name).owner
54
-
55
- if owner.instance_of?(::Class)
56
- owner < ::OpenStruct
57
- else
58
- self.class.ancestors.any? do |mod|
59
- return false if mod == ::OpenStruct
60
-
61
- mod == owner
62
- end
63
- end
64
- end
65
- # rubocop:enable Metrics/MethodLength, Naming/PredicateName
66
-
67
- def new_ostruct_member!(name)
68
- return if is_method_protected!(name)
69
-
70
- method = 'define_singleton_method'
71
- method << '!' if respond_to?(:define_singleton_method!)
72
-
73
- send(method, name) { @table[name] }
74
- send(method, "#{name}=") { |x| @table[name] = x }
75
- end
76
-
77
29
  end
78
30
  end
@@ -5,9 +5,7 @@ class Object
5
5
  def blank?
6
6
  object = self
7
7
  object = object.strip if respond_to?(:strip)
8
- return object.empty? if respond_to?(:empty?)
9
-
10
- !object
8
+ respond_to?(:empty?) ? object.empty? : !object
11
9
  end
12
10
 
13
11
  def deep_dup
@@ -26,15 +24,19 @@ class Object
26
24
  self if present?
27
25
  end
28
26
 
29
- def try(*obj, &block)
30
- try!(*obj, &block) if obj.empty? || respond_to?(obj.first)
27
+ def try(method_name = nil, *args, &block)
28
+ if method_name.nil? && block
29
+ block.arity.zero? ? instance_eval(&block) : yield(self)
30
+ elsif respond_to?(method_name)
31
+ public_send(method_name, *args, &block)
32
+ end
31
33
  end
32
34
 
33
- def try!(*obj, &block)
34
- if obj.empty? && defined?(yield)
35
+ def try!(method_name = nil, *args, &block)
36
+ if method_name.nil? && block
35
37
  block.arity.zero? ? instance_eval(&block) : yield(self)
36
38
  else
37
- public_send(*obj, &block)
39
+ public_send(method_name, *args, &block)
38
40
  end
39
41
  end
40
42
 
@@ -3,20 +3,12 @@
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('struct')
4
4
  class Struct
5
5
 
6
- def [](key)
7
- attributes[key.to_sym]
8
- end
9
-
10
- def []=(key, val)
11
- send("#{key}=", val)
12
- end
13
-
14
6
  def attributes
15
7
  each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
16
8
  end
17
9
 
18
10
  def replace(args)
19
- args.each_pair { |key, val| send("#{key}=", val) }
11
+ args.each_pair { |key, val| self[key] = val }
20
12
  end
21
13
 
22
14
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION = '1.1.15'
6
+ VERSION = '1.3.2'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.15
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-05 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubygems_version: 3.2.19
225
+ rubygems_version: 3.2.24
226
226
  signing_key:
227
227
  specification_version: 4
228
228
  summary: Collection of useful Ruby methods for its primitive classes