defi 2.0.0 → 2.0.5
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 +4 -4
- data/LICENSE.md +1 -1
- data/README.md +16 -47
- data/lib/defi.rb +1 -5
- data/lib/defi/challenge.rb +11 -26
- data/lib/defi/value.rb +4 -21
- metadata +51 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a5d9ec9fab69bff15c96a7cc69fa4803ae518de50757ec42b4e2f2189df4ae8
|
4
|
+
data.tar.gz: 942186c2634f4ed5fafd96fa811444105ac6b0983627d1bb2023e004dfb403df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 780386f4f728d69dc3b904b0773fc6a01c712d9f8857102cd3e0a142a5400cff2db9f2ae2693a682bfe3c83a83ab3d1fad743d44db4495d0ed398155c081755b
|
7
|
+
data.tar.gz: 2d7352dd2e198709f43de97312e904836a6fc00a234c5b31b5cb4e01dc3904f6b43ed70828578e635bb0cdd80531b20ad84eafaf5c21eae3a3881d26f5414516
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,18 @@
|
|
1
1
|
# Defi
|
2
2
|
|
3
|
-
[][codeclimate]
|
3
|
+
[][travis]
|
5
4
|
[][gem]
|
6
|
-
[][inchpages]
|
7
6
|
[][rubydoc]
|
8
7
|
|
9
8
|
> Challenge library.
|
10
9
|
|
11
|
-
## Contact
|
12
|
-
|
13
|
-
* Home page: https://github.com/fixrb/defi
|
14
|
-
* Bugs/issues: https://github.com/fixrb/defi/issues
|
15
|
-
|
16
|
-
## Rubies
|
17
|
-
|
18
|
-
* [MRI](https://www.ruby-lang.org/)
|
19
|
-
* [Rubinius](https://rubinius.com/)
|
20
|
-
* [JRuby](https://www.jruby.org/)
|
21
|
-
|
22
10
|
## Installation
|
23
11
|
|
24
12
|
Add this line to your application's Gemfile:
|
25
13
|
|
26
14
|
```ruby
|
27
|
-
gem
|
15
|
+
gem "defi"
|
28
16
|
```
|
29
17
|
|
30
18
|
And then execute:
|
@@ -46,58 +34,39 @@ Defi.send(:*, 7).to(6).call # => 42
|
|
46
34
|
Now, let's challenge "`foo`" with `boom` method:
|
47
35
|
|
48
36
|
```ruby
|
49
|
-
Defi.send(:boom).to(
|
37
|
+
Defi.send(:boom).to("foo").call # NoMethodError: undefined method `boom' for "foo":String
|
50
38
|
```
|
51
39
|
|
52
40
|
Let's challenge "`hello world`" with `gsub!` in isolation:
|
53
41
|
|
54
42
|
```ruby
|
55
|
-
some_text =
|
56
|
-
Defi.send(:gsub!,
|
43
|
+
some_text = "hello world"
|
44
|
+
Defi.send(:gsub!, "world", "Alice").to!(some_text).call # => "hello Alice"
|
57
45
|
some_text # => "hello world"
|
58
46
|
```
|
59
47
|
|
60
|
-
##
|
61
|
-
|
62
|
-
As a basic form of security __Defi__ provides a set of SHA512 checksums for
|
63
|
-
every Gem release. These checksums can be found in the `checksum/` directory.
|
64
|
-
Although these checksums do not prevent malicious users from tampering with a
|
65
|
-
built Gem they can be used for basic integrity verification purposes.
|
66
|
-
|
67
|
-
The checksum of a file can be checked using the `sha512sum` command. For
|
68
|
-
example:
|
48
|
+
## Contact
|
69
49
|
|
70
|
-
|
71
|
-
c30380a253c932bbff42a36611466f2b7d59e6a1d9578a4989e7b2cfd4078cf9d64e452b0eaa055c5ab88be4816d3f366d7aa705d29bb54e2db9f75d21f36cf7 pkg/defi-1.0.0.gem
|
50
|
+
* Source code: https://github.com/fixrb/defi/issues
|
72
51
|
|
73
52
|
## Versioning
|
74
53
|
|
75
54
|
__Defi__ follows [Semantic Versioning 2.0](https://semver.org/).
|
76
55
|
|
77
|
-
## Contributing
|
78
|
-
|
79
|
-
1. [Fork it](https://github.com/fixrb/defi/fork)
|
80
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
-
5. Create a new Pull Request
|
84
|
-
|
85
56
|
## License
|
86
57
|
|
87
|
-
|
88
|
-
|
89
|
-
[gem]: https://rubygems.org/gems/defi
|
90
|
-
[travis]: https://travis-ci.org/fixrb/defi
|
91
|
-
[codeclimate]: https://codeclimate.com/github/fixrb/defi
|
92
|
-
[inchpages]: https://inch-ci.org/github/fixrb/defi
|
93
|
-
[rubydoc]: https://rubydoc.info/gems/defi/frames
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
94
59
|
|
95
60
|
***
|
96
61
|
|
97
62
|
<p>
|
98
|
-
This project is sponsored by
|
99
|
-
|
63
|
+
This project is sponsored by:<br />
|
100
64
|
<a href="https://sashite.com/"><img
|
101
|
-
src="https://github.com/fixrb/defi/raw/
|
65
|
+
src="https://github.com/fixrb/defi/raw/main/img/sashite.png"
|
102
66
|
alt="Sashite" /></a>
|
103
67
|
</p>
|
68
|
+
|
69
|
+
[gem]: https://rubygems.org/gems/defi
|
70
|
+
[travis]: https://travis-ci.org/fixrb/defi
|
71
|
+
[inchpages]: https://inch-ci.org/github/fixrb/defi
|
72
|
+
[rubydoc]: https://rubydoc.info/gems/defi/frames
|
data/lib/defi.rb
CHANGED
@@ -2,13 +2,9 @@
|
|
2
2
|
|
3
3
|
# Namespace for the Defi library.
|
4
4
|
#
|
5
|
-
# @api public
|
6
|
-
#
|
7
5
|
module Defi
|
8
6
|
# Expectations are built with this method.
|
9
7
|
#
|
10
|
-
# @api public
|
11
|
-
#
|
12
8
|
# @example The challenge
|
13
9
|
# send(:foo) # => #<Defi::Challenge:0x007f96a40925f8 @method=:foo, @args=[]>
|
14
10
|
#
|
@@ -23,4 +19,4 @@ module Defi
|
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
26
|
-
require_relative File.join(
|
22
|
+
require_relative File.join("defi", "challenge")
|
data/lib/defi/challenge.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "aw"
|
4
4
|
|
5
5
|
module Defi
|
6
6
|
# This class contains a challenge to apply against an object.
|
7
|
-
#
|
8
|
-
# @api private
|
9
|
-
#
|
10
7
|
class Challenge < ::BasicObject
|
11
8
|
# Initialize the challenge class.
|
12
9
|
#
|
13
|
-
# @api private
|
14
|
-
#
|
15
10
|
# @param method [#to_sym] The method to send to an object.
|
16
11
|
# @param args [Array] Any arguments of the method.
|
17
12
|
# @param opts [Hash] Any keyword arguments of the method.
|
@@ -23,8 +18,6 @@ module Defi
|
|
23
18
|
@block = block
|
24
19
|
end
|
25
20
|
|
26
|
-
# @api public
|
27
|
-
#
|
28
21
|
# @param object [#object_id] The object to challenge.
|
29
22
|
#
|
30
23
|
# @return [Defi::Value] The actual value, to raise or to return.
|
@@ -32,8 +25,6 @@ module Defi
|
|
32
25
|
Value.new { object.public_send(@method, *@args, **@opts, &@block) }
|
33
26
|
end
|
34
27
|
|
35
|
-
# @api public
|
36
|
-
#
|
37
28
|
# @param object [#object_id] The object to challenge in code isolation.
|
38
29
|
#
|
39
30
|
# @return [Defi::Value] The actual value, to raise or to return.
|
@@ -45,8 +36,6 @@ module Defi
|
|
45
36
|
|
46
37
|
# Properties of the challenge.
|
47
38
|
#
|
48
|
-
# @api public
|
49
|
-
#
|
50
39
|
# @return [Hash] The properties of the challenge.
|
51
40
|
def to_h
|
52
41
|
{
|
@@ -59,8 +48,6 @@ module Defi
|
|
59
48
|
|
60
49
|
# String of the challenge.
|
61
50
|
#
|
62
|
-
# @api public
|
63
|
-
#
|
64
51
|
# @return [String] The string representation of the challenge.
|
65
52
|
def to_s
|
66
53
|
string = ".#{@method}"
|
@@ -69,9 +56,9 @@ module Defi
|
|
69
56
|
|
70
57
|
stringified_args = @args.inspect[1..-2]
|
71
58
|
stringified_opts = @opts.inspect[1..-2]
|
72
|
-
stringified_block =
|
59
|
+
stringified_block = "<Proc>" unless @block.nil?
|
73
60
|
|
74
|
-
string +=
|
61
|
+
string += "("
|
75
62
|
|
76
63
|
stringified_items = []
|
77
64
|
|
@@ -79,28 +66,26 @@ module Defi
|
|
79
66
|
stringified_items << stringified_opts unless @opts.empty?
|
80
67
|
stringified_items << stringified_block unless @block.nil?
|
81
68
|
|
82
|
-
string
|
69
|
+
"#{string}#{stringified_items.join(', ')})"
|
83
70
|
end
|
84
71
|
|
85
72
|
# A string containing a human-readable representation of the challenge.
|
86
73
|
#
|
87
|
-
# @api public
|
88
|
-
#
|
89
74
|
# @return [String] The human-readable representation of the challenge.
|
90
75
|
def inspect
|
91
76
|
inspected_method = @method.inspect
|
92
77
|
inspected_args = @args.inspect
|
93
78
|
inspected_opts = @opts.inspect
|
94
|
-
inspected_block = @block.nil? ?
|
79
|
+
inspected_block = @block.nil? ? "nil" : "<Proc>"
|
95
80
|
|
96
|
-
|
81
|
+
"Defi(" \
|
97
82
|
"method: #{inspected_method}, " \
|
98
|
-
"args: #{
|
99
|
-
"opts: #{
|
100
|
-
"block: #{
|
101
|
-
|
83
|
+
"args: #{inspected_args}, " \
|
84
|
+
"opts: #{inspected_opts}, " \
|
85
|
+
"block: #{inspected_block}" \
|
86
|
+
")"
|
102
87
|
end
|
103
88
|
end
|
104
89
|
end
|
105
90
|
|
106
|
-
require_relative
|
91
|
+
require_relative "value"
|
data/lib/defi/value.rb
CHANGED
@@ -3,20 +3,16 @@
|
|
3
3
|
module Defi
|
4
4
|
# This class contains an object that returned or raised during the initialize.
|
5
5
|
#
|
6
|
-
# @api private
|
7
|
-
#
|
8
6
|
class Value
|
9
7
|
# @return [#object_id] The returned or the raised object.
|
10
8
|
attr_reader :object
|
11
9
|
|
12
10
|
# Initialize the value class.
|
13
11
|
#
|
14
|
-
# @
|
15
|
-
#
|
16
|
-
# @param block [Proc] The block of code to execute.
|
12
|
+
# @yieldreturn [#object_id] The challenged code.
|
17
13
|
# rubocop:disable Lint/RescueException
|
18
|
-
def initialize
|
19
|
-
@object =
|
14
|
+
def initialize
|
15
|
+
@object = yield
|
20
16
|
@raised = false
|
21
17
|
rescue ::Exception => e
|
22
18
|
@object = e
|
@@ -33,8 +29,6 @@ module Defi
|
|
33
29
|
object
|
34
30
|
end
|
35
31
|
|
36
|
-
# @api public
|
37
|
-
#
|
38
32
|
# @return [Boolean] The value was raised (or returned)?
|
39
33
|
def raised?
|
40
34
|
@raised
|
@@ -42,8 +36,6 @@ module Defi
|
|
42
36
|
|
43
37
|
# Properties of the value.
|
44
38
|
#
|
45
|
-
# @api public
|
46
|
-
#
|
47
39
|
# @return [Hash] The properties of the value.
|
48
40
|
def to_h
|
49
41
|
{
|
@@ -54,23 +46,14 @@ module Defi
|
|
54
46
|
|
55
47
|
# String of the value.
|
56
48
|
#
|
57
|
-
# @api public
|
58
|
-
#
|
59
49
|
# @return [String] The string representation of the value.
|
60
50
|
def to_s
|
61
|
-
string =
|
62
|
-
'raise'
|
63
|
-
else
|
64
|
-
'return'
|
65
|
-
end
|
66
|
-
|
51
|
+
string = raised? ? "raise" : "return"
|
67
52
|
"#{string} #{object}"
|
68
53
|
end
|
69
54
|
|
70
55
|
# A string containing a human-readable representation of the value.
|
71
56
|
#
|
72
|
-
# @api public
|
73
|
-
#
|
74
57
|
# @return [String] The human-readable representation of the value.
|
75
58
|
def inspect
|
76
59
|
"Value(object: #{object}, raised: #{raised?})"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aw
|
@@ -16,44 +16,44 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.12
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.12
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
56
|
+
name: rubocop-md
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -80,34 +80,62 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-thread_safety
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: simplecov
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
117
|
+
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: yard
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
|
-
- - "
|
129
|
+
- - ">="
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0
|
131
|
+
version: '0'
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
|
-
- - "
|
136
|
+
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0
|
138
|
+
version: '0'
|
111
139
|
description: Challenge library.
|
112
140
|
email: contact@cyril.email
|
113
141
|
executables: []
|
@@ -131,14 +159,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
159
|
requirements:
|
132
160
|
- - ">="
|
133
161
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
162
|
+
version: 2.7.0
|
135
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
164
|
requirements:
|
137
165
|
- - ">="
|
138
166
|
- !ruby/object:Gem::Version
|
139
167
|
version: '0'
|
140
168
|
requirements: []
|
141
|
-
rubygems_version: 3.1.
|
169
|
+
rubygems_version: 3.1.4
|
142
170
|
signing_key:
|
143
171
|
specification_version: 4
|
144
172
|
summary: Challenge library.
|