stub_requests 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -3
- data/Rakefile +6 -0
- data/lib/stub_requests/core_ext/array/extract_options.rb +3 -3
- data/lib/stub_requests/core_ext/class/attribute.rb +38 -40
- data/lib/stub_requests/core_ext/kernel/singleton_class.rb +4 -6
- data/lib/stub_requests/core_ext/module/redefine_method.rb +37 -39
- data/lib/stub_requests/core_ext/object/blank.rb +83 -84
- data/lib/stub_requests/core_ext/string/to_route_param.rb +1 -1
- data/lib/stub_requests/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4dcfcb95fc0084e09f59ae295b6244b9f08fe11a284b7ee3e7df9d988d4c832
|
4
|
+
data.tar.gz: 38716732dc7d96ccab33752e7e097f324ce1c3c4d2d588bce7397bdec996a24d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c07523bea4f8fe8ed44df67862e29c46030aca348ea3f1c962a2040f02ce519292c468a4b753d76656afa08c839b4bfb936835bfa350cc15a5302cf6121036c
|
7
|
+
data.tar.gz: 926410d4326bf53974c8074bd2072d465a1f5fabb052794477a16e39440527ad0fcc55cf4a8d602bd1afa4a2a1b3bd56b6accf3030267198b7aa414b8207ba40
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [
|
4
|
-
|
5
|
-
[Full Changelog](https://github.com/mhenrixon/stub_requests/compare/v0.1.4...HEAD)
|
3
|
+
## [v0.1.5](https://github.com/mhenrixon/stub_requests/tree/v0.1.5) (2019-02-06)
|
4
|
+
[Full Changelog](https://github.com/mhenrixon/stub_requests/compare/v0.1.4...v0.1.5)
|
6
5
|
|
7
6
|
**Implemented enhancements:**
|
8
7
|
|
@@ -15,6 +14,7 @@
|
|
15
14
|
|
16
15
|
**Merged pull requests:**
|
17
16
|
|
17
|
+
- Update Changelog [\#20](https://github.com/mhenrixon/stub_requests/pull/20) ([mhenrixon](https://github.com/mhenrixon))
|
18
18
|
- Update Changelog [\#16](https://github.com/mhenrixon/stub_requests/pull/16) ([mhenrixon](https://github.com/mhenrixon))
|
19
19
|
|
20
20
|
## [v0.1.4](https://github.com/mhenrixon/stub_requests/tree/v0.1.4) (2019-02-06)
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ class Hash
|
|
5
5
|
# @api private
|
6
6
|
def extractable_options?
|
7
7
|
instance_of?(Hash)
|
8
|
-
end
|
8
|
+
end unless method_defined?(:extractable_options?)
|
9
9
|
end
|
10
10
|
|
11
11
|
# :nodoc:
|
@@ -17,7 +17,7 @@ class Array
|
|
17
17
|
else
|
18
18
|
{}
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end unless method_defined?(:extract_options!)
|
21
21
|
|
22
22
|
# :nodoc:
|
23
23
|
def extract_options
|
@@ -26,5 +26,5 @@ class Array
|
|
26
26
|
else
|
27
27
|
{}
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end unless method_defined?(:extract_options)
|
30
30
|
end
|
@@ -1,60 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# :nodoc:
|
4
|
+
class Class
|
4
5
|
# :nodoc:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
options = attrs.extract_options!
|
9
|
-
default_value = options.fetch(:default, nil)
|
6
|
+
def class_attribute(*attrs)
|
7
|
+
options = attrs.extract_options!
|
8
|
+
default_value = options.fetch(:default, nil)
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
attrs.each do |name|
|
11
|
+
singleton_class.silence_redefinition_of_method(name)
|
12
|
+
define_singleton_method(name) { nil }
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
singleton_class.silence_redefinition_of_method("#{name}?")
|
15
|
+
define_singleton_method("#{name}?") { !!public_send(name) }
|
17
16
|
|
18
|
-
|
17
|
+
ivar = "@#{name}"
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
singleton_class.silence_redefinition_of_method("#{name}=")
|
20
|
+
define_singleton_method("#{name}=") do |val|
|
21
|
+
singleton_class.class_eval do
|
22
|
+
redefine_method(name) { val }
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
25
|
+
if singleton_class?
|
26
|
+
class_eval do
|
27
|
+
redefine_method(name) do
|
28
|
+
if instance_variable_defined? ivar
|
29
|
+
instance_variable_get ivar
|
30
|
+
else
|
31
|
+
singleton_class.send name
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
37
|
-
val
|
38
35
|
end
|
36
|
+
val
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
39
|
+
redefine_method(name) do
|
40
|
+
if instance_variable_defined?(ivar)
|
41
|
+
instance_variable_get ivar
|
42
|
+
else
|
43
|
+
self.class.public_send name
|
46
44
|
end
|
45
|
+
end
|
47
46
|
|
48
|
-
|
47
|
+
redefine_method("#{name}?") { !!public_send(name) }
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
redefine_method("#{name}=") do |val|
|
50
|
+
instance_variable_set ivar, val
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
53
|
+
unless default_value.nil?
|
54
|
+
self.send("#{name}=", default_value)
|
57
55
|
end
|
58
56
|
end
|
59
|
-
end
|
57
|
+
end unless method_defined?(:class_attribute)
|
60
58
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# :nodoc:
|
4
|
+
module Kernel
|
4
5
|
# :nodoc:
|
5
|
-
|
6
|
-
|
7
|
-
def class_eval(*args, &block)
|
8
|
-
singleton_class.class_eval(*args, &block)
|
9
|
-
end
|
6
|
+
def class_eval(*args, &block)
|
7
|
+
singleton_class.class_eval(*args, &block)
|
10
8
|
end
|
11
9
|
end
|
@@ -2,49 +2,47 @@
|
|
2
2
|
|
3
3
|
# :nodoc:
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# See {Module}
|
6
|
+
# @api private
|
7
|
+
class Module
|
7
8
|
# @api private
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
alias_method :__rails_redefine, method
|
14
|
-
remove_method :__rails_redefine
|
15
|
-
end
|
9
|
+
# :nodoc:
|
10
|
+
def silence_redefinition_of_method(method)
|
11
|
+
if method_defined?(method) || private_method_defined?(method)
|
12
|
+
alias_method :__stub_requests_redefine, method
|
13
|
+
remove_method :__stub_requests_redefine
|
16
14
|
end
|
15
|
+
end unless method_defined?(:silence_redefinition_of_method)
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
# Replaces the existing method definition, if there is one, with the passed
|
18
|
+
# block as its body.
|
19
|
+
# @api private
|
20
|
+
# :nodoc:
|
21
|
+
def redefine_method(method, &block)
|
22
|
+
visibility = method_visibility(method)
|
23
|
+
silence_redefinition_of_method(method)
|
24
|
+
define_method(method, &block)
|
25
|
+
send(visibility, method)
|
26
|
+
end unless method_defined?(:redefine_method)
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# Replaces the existing singleton method definition, if there is one, with
|
29
|
+
# the passed block as its body.
|
30
|
+
# @api private
|
31
|
+
# :nodoc:
|
32
|
+
def redefine_singleton_method(method, &block)
|
33
|
+
singleton_class.redefine_method(method, &block)
|
34
|
+
end unless method_defined?(:redefine_singleton_method)
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
36
|
+
# @api private
|
37
|
+
# :nodoc:
|
38
|
+
def method_visibility(method) # :nodoc:
|
39
|
+
case
|
40
|
+
when private_method_defined?(method)
|
41
|
+
:private
|
42
|
+
when protected_method_defined?(method)
|
43
|
+
:protected
|
44
|
+
else
|
45
|
+
:public
|
48
46
|
end
|
49
|
-
end
|
47
|
+
end unless method_defined?(:method_visibility)
|
50
48
|
end
|
@@ -2,113 +2,112 @@
|
|
2
2
|
|
3
3
|
# Copied from https://raw.githubusercontent.com/rails/rails/d66e7835bea9505f7003e5038aa19b6ea95ceea1/activesupport/lib/active_support/core_ext/object/blank.rb
|
4
4
|
|
5
|
-
|
5
|
+
# :nodoc:
|
6
|
+
class Object
|
7
|
+
# :nodoc:
|
8
|
+
def blank?
|
9
|
+
respond_to?(:empty?) ? !!empty? : !self # rubocop:disable Style/DoubleNegation
|
10
|
+
end unless method_defined?(:blank?)
|
6
11
|
|
7
12
|
# :nodoc:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
respond_to?(:empty?) ? !!empty? : !self # rubocop:disable Style/DoubleNegation
|
12
|
-
end
|
13
|
-
# :nodoc:
|
14
|
-
def present?
|
15
|
-
!blank?
|
16
|
-
end
|
17
|
-
# :nodoc:
|
18
|
-
def presence
|
19
|
-
self if present?
|
20
|
-
end
|
21
|
-
end
|
13
|
+
def present?
|
14
|
+
!blank?
|
15
|
+
end unless method_defined?(:present?)
|
22
16
|
|
23
|
-
# @see NilClass
|
24
17
|
# :nodoc:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
18
|
+
def presence
|
19
|
+
self if present?
|
20
|
+
end unless method_defined?(:presence)
|
21
|
+
end
|
31
22
|
|
32
|
-
|
23
|
+
# @see NilClass
|
24
|
+
# :nodoc:
|
25
|
+
class NilClass
|
33
26
|
# :nodoc:
|
34
|
-
|
35
|
-
|
36
|
-
def blank?
|
37
|
-
true
|
38
|
-
end
|
27
|
+
def blank?
|
28
|
+
true
|
39
29
|
end
|
30
|
+
end
|
40
31
|
|
41
|
-
|
32
|
+
# @see FalseClass
|
33
|
+
# :nodoc:
|
34
|
+
class FalseClass
|
42
35
|
# :nodoc:
|
43
|
-
|
44
|
-
|
45
|
-
def blank?
|
46
|
-
false
|
47
|
-
end
|
36
|
+
def blank?
|
37
|
+
true
|
48
38
|
end
|
39
|
+
end
|
49
40
|
|
50
|
-
|
41
|
+
# @see TrueClass
|
42
|
+
# :nodoc:
|
43
|
+
class TrueClass
|
51
44
|
# :nodoc:
|
52
|
-
|
53
|
-
|
54
|
-
alias blank? empty?
|
45
|
+
def blank?
|
46
|
+
false
|
55
47
|
end
|
48
|
+
end
|
56
49
|
|
57
|
-
|
50
|
+
# @see Array
|
51
|
+
# :nodoc:
|
52
|
+
class Array
|
58
53
|
# :nodoc:
|
59
|
-
|
60
|
-
|
61
|
-
alias blank? empty?
|
62
|
-
end
|
54
|
+
alias blank? empty?
|
55
|
+
end
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# :nodoc:
|
71
|
-
ENCODED_BLANKS = Concurrent::Map.new do |map, enc|
|
72
|
-
map[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
|
73
|
-
end
|
57
|
+
# @see Hash
|
58
|
+
# :nodoc:
|
59
|
+
class Hash
|
60
|
+
# :nodoc:
|
61
|
+
alias blank? empty?
|
62
|
+
end
|
74
63
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
64
|
+
# @see String
|
65
|
+
class String
|
66
|
+
# :nodoc:
|
67
|
+
# :nodoc:
|
68
|
+
BLANK_RE = /\A[[:space:]]*\z/.freeze
|
69
|
+
# :nodoc:
|
70
|
+
# :nodoc:
|
71
|
+
ENCODED_BLANKS = Concurrent::Map.new do |map, enc|
|
72
|
+
map[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
|
73
|
+
end
|
74
|
+
|
75
|
+
# :nodoc:
|
76
|
+
def blank?
|
77
|
+
# The regexp that matches blank strings is expensive. For the case of empty
|
78
|
+
# strings we can speed up this method (~3.5x) with an empty? call. The
|
79
|
+
# penalty for the rest of strings is marginal.
|
80
|
+
empty? ||
|
81
|
+
begin
|
82
|
+
if RUBY_VERSION >= "2.4"
|
83
|
+
BLANK_RE.match?(self)
|
84
|
+
else
|
85
|
+
!!BLANK_RE.match(self)
|
86
|
+
end
|
87
|
+
rescue Encoding::CompatibilityError
|
88
|
+
if RUBY_VERSION >= "2.4"
|
89
|
+
ENCODED_BLANKS[encoding].match?(self)
|
90
|
+
else
|
91
|
+
!!ENCODED_BLANKS[encoding].match(self)
|
93
92
|
end
|
94
|
-
|
93
|
+
end
|
95
94
|
end
|
95
|
+
end
|
96
96
|
|
97
|
-
|
97
|
+
# @see Numeric
|
98
|
+
# :nodoc:
|
99
|
+
class Numeric
|
98
100
|
# :nodoc:
|
99
|
-
|
100
|
-
|
101
|
-
def blank?
|
102
|
-
false
|
103
|
-
end
|
101
|
+
def blank?
|
102
|
+
false
|
104
103
|
end
|
104
|
+
end
|
105
105
|
|
106
|
-
|
106
|
+
# @see Time
|
107
|
+
# :nodoc:
|
108
|
+
class Time
|
107
109
|
# :nodoc:
|
108
|
-
|
109
|
-
|
110
|
-
def blank?
|
111
|
-
false
|
112
|
-
end
|
110
|
+
def blank?
|
111
|
+
false
|
113
112
|
end
|
114
113
|
end
|