finapps_core 2.0.15 → 2.0.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13f4ba86a94de3e1ca4e6aff4ce2cf64dfbbb423
4
- data.tar.gz: ca6db24c7d989854b484e200efcc4d97aff7dd83
3
+ metadata.gz: e8289131ef370466de3c40eb0cc59b57bc827fe3
4
+ data.tar.gz: 1db42e4b79ba6cb447a25de5123f94f38a287d54
5
5
  SHA512:
6
- metadata.gz: ecf9432bd8c9000dc9a7558d631d07b1a667d76ad60f999e0b755953af7cc24c15f0159c3be0c1f558afe45f003659472849cd321ecfa308df3841efa2f7e0e1
7
- data.tar.gz: ee47b4f66598ecefb87921ec2c2b4cb1a1b3b608a85ac4aad1808120123faaf8408defbb02bf07595151c8a3d8e5e36254ede7e78da4b07aef33c27d545200de
6
+ metadata.gz: 5b04fa8f805fe745ebe92066a91a62d045b0498a21376afb4607bdfc576cd1e0b2ef3427e02cb9a420afd2cdf8aceea876339a01d9464cebccfb0ba9eba4b4b0
7
+ data.tar.gz: 12a997ffd3eee2e90d47efd9088f02295c7519be4f4299a95fe3a6d13f4f4d741008569618dbd2405567ad773f8c7cc73aa95ec384abfc82998a8655fd577446
@@ -33,7 +33,7 @@ module FinAppsCore
33
33
  private
34
34
 
35
35
  def error_messages(body)
36
- return nil if body.blank?
36
+ return nil if !body || (body.respond_to?(:empty?) && body.empty?)
37
37
  body = body.json_to_hash if body.is_a?(String)
38
38
  has_message_key?(body) ? body['messages'] : nil
39
39
  end
@@ -72,7 +72,11 @@ module FinAppsCore
72
72
  private
73
73
 
74
74
  def empty?(response)
75
- response.blank? || (response.respond_to?(:body) && response.body.blank?)
75
+ !response || empty_body?(response)
76
+ end
77
+
78
+ def empty_body?(response)
79
+ response.respond_to?(:body) && (!response.body || (response.body.respond_to?(:empty?) && response.body.empty?))
76
80
  end
77
81
 
78
82
  def execute_request(path, method, params)
@@ -100,7 +104,7 @@ module FinAppsCore
100
104
 
101
105
  def handle_client_error(error)
102
106
  logger.warn "#{self.class}##{__method__} => #{error.class.name}, #{error}"
103
- error.response.present? && error.response[:error_messages] ? error.response[:error_messages] : [error.message]
107
+ error.response && error.response[:error_messages] ? error.response[:error_messages] : [error.message]
104
108
  end
105
109
 
106
110
  def execute_method(path, method, params)
@@ -3,9 +3,6 @@ module FinAppsCore
3
3
  module REST
4
4
  # represents both tenant and user credentials
5
5
  class Credentials
6
- using ObjectExtensions
7
- using StringExtensions
8
-
9
6
  attr_reader :identifier, :token
10
7
 
11
8
  def initialize(identifier, token)
@@ -14,7 +11,7 @@ module FinAppsCore
14
11
  end
15
12
 
16
13
  def valid?
17
- identifier.present? && token.present?
14
+ !identifier.nil? && !token.nil?
18
15
  end
19
16
  end
20
17
  end
@@ -7,7 +7,14 @@ module FinAppsCore
7
7
  # Adds validation capabilities when included into other classes
8
8
  module Validatable
9
9
  def not_blank(value, name=nil)
10
- raise FinAppsCore::MissingArgumentsError.new "Missing argument#{": #{name}" unless name.nil?}" if value.blank?
10
+ if nil_or_empty?(value)
11
+ argument_name = name.nil? ? nil : ": #{name}"
12
+ raise FinAppsCore::MissingArgumentsError.new "Missing argument#{argument_name}"
13
+ end
14
+ end
15
+
16
+ def nil_or_empty?(value)
17
+ !value || (value.respond_to?(:empty) && value.empty?)
11
18
  end
12
19
  end
13
20
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module FinAppsCore
3
- VERSION = '2.0.15'
3
+ VERSION = '2.0.16'
4
4
  end
data/lib/finapps_core.rb CHANGED
@@ -6,7 +6,6 @@ require 'faraday_middleware'
6
6
  require 'typhoeus'
7
7
  require 'typhoeus/adapters/faraday'
8
8
 
9
- require 'core_extensions/object/blank'
10
9
  require 'core_extensions/object/is_integer'
11
10
  require 'core_extensions/string/json_to_hash'
12
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finapps_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.15
4
+ version: 2.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
@@ -292,7 +292,6 @@ files:
292
292
  - README.md
293
293
  - Rakefile
294
294
  - finapps_core.gemspec
295
- - lib/core_extensions/object/blank.rb
296
295
  - lib/core_extensions/object/is_integer.rb
297
296
  - lib/core_extensions/string/json_to_hash.rb
298
297
  - lib/finapps_core.rb
@@ -315,7 +314,6 @@ files:
315
314
  - lib/finapps_core/utils/validatable.rb
316
315
  - lib/finapps_core/version.rb
317
316
  - lib/tasks/releaser.rake
318
- - spec/core_extensions/object/blank_spec.rb
319
317
  - spec/core_extensions/object/is_integer_spec.rb
320
318
  - spec/middleware/request/accept_json_spec.rb
321
319
  - spec/middleware/request/no_encoding_basic_authentication_spec.rb
@@ -378,7 +376,6 @@ test_files:
378
376
  - spec/spec_helpers/client.rb
379
377
  - spec/spec_helper.rb
380
378
  - spec/core_extensions/object/is_integer_spec.rb
381
- - spec/core_extensions/object/blank_spec.rb
382
379
  - spec/middleware/request/no_encoding_basic_authentication_spec.rb
383
380
  - spec/middleware/request/user_agent_spec.rb
384
381
  - spec/middleware/request/tenant_authentication_spec.rb
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
- module ObjectExtensions
3
- refine Object do
4
- # An object is blank if it's false, empty, or a whitespace string.
5
- # For example, +false+, '', ' ', +nil+, [], and {} are all blank.
6
- #
7
- # This simplifies
8
- #
9
- # !address || address.empty?
10
- #
11
- # to
12
- #
13
- # address.blank?
14
- #
15
- # @return [true, false]
16
- def blank?
17
- respond_to?(:empty?) ? !!empty? : !self
18
- end
19
-
20
- # An object is present if it's not blank.
21
- #
22
- # @return [true, false]
23
- def present?
24
- !blank?
25
- end
26
- end
27
- end
28
-
29
- module StringExtensions
30
- refine String do
31
- BLANK_RE = /\A[[:space:]]*\z/
32
-
33
- # A string is blank if it's empty or contains whitespaces only:
34
- #
35
- # ''.blank? # => true
36
- # ' '.blank? # => true
37
- # "\t\n\r".blank? # => true
38
- # ' blah '.blank? # => false
39
- #
40
- # Unicode whitespace is supported:
41
- #
42
- # "\u00a0".blank? # => true
43
- #
44
- # @return [true, false]
45
- def blank?
46
- match BLANK_RE
47
- end
48
- end
49
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
- using ObjectExtensions
3
-
4
- RSpec.describe ObjectExtensions do
5
- context 'when refining Object' do
6
- describe '#blank?' do
7
- # An object is blank if it's false, empty, or a whitespace string.
8
- context 'for false' do
9
- it { expect(false.blank?).to eq(true) }
10
- end
11
- context 'for empty arrays' do
12
- it { expect([].blank?).to eq(true) }
13
- end
14
- context 'for empty hashes' do
15
- it { expect({}.blank?).to eq(true) }
16
- end
17
- context 'for whitespace string' do
18
- it { expect(''.blank?).to eq(true) }
19
- end
20
- end
21
-
22
- describe '#present?' do
23
- # An object is present if it's not blank.
24
- context 'for not blank objects' do
25
- it { expect(1.present?).to eq(true) }
26
- end
27
-
28
- context 'for blank objects' do
29
- it { expect(false.present?).to eq(false) }
30
- end
31
- end
32
- end
33
- end