much-not-given 0.0.1 → 0.1.0
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/README.md +25 -2
- data/lib/much-not-given.rb +47 -0
- data/lib/much-not-given/version.rb +1 -1
- data/much-not-given.gemspec +2 -0
- data/test/unit/much-not-given_tests.rb +55 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7555cfcec030086658ffb01b7f307c95d83255e6ae83c781814644ec4e1d84ca
|
4
|
+
data.tar.gz: 5a2b58ad8bc2dc1327b7fc6d9071465b889d72f57896ffda98723216c0cf8252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6959d530476fd6745fdbbf3e53e9080da811d3fc8ace494489d01ccdc429fa16fe50ed1388aaaf54042d02ae3ab990f2ea10d3f5b48db6fda0f5dd088f675298
|
7
|
+
data.tar.gz: 6438f7633f583ecaeb17a5b3c311baf89efeba546312d22c734dd3a9925297c2261298ef304c3e079460eea621b802591890af8e24cff4298acd41019441d2c3
|
data/README.md
CHANGED
@@ -1,10 +1,33 @@
|
|
1
1
|
# MuchNotGiven
|
2
2
|
|
3
|
-
Add "not given" default values to your objects.
|
3
|
+
Add "not given" default values to your objects. This allows you to safely detect whether a method has been given argument values or not.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
|
7
|
+
```ruby
|
8
|
+
module MyNamespace
|
9
|
+
include MuchNotGiven
|
10
|
+
end
|
11
|
+
|
12
|
+
MyNamespace.not_given # => MyNamespace.not_given
|
13
|
+
"some value" == MyNamespace.not_given # => false
|
14
|
+
MyNamespace.not_given?("some value") # => false
|
15
|
+
MyNamespace.not_given?(MyNamespace.not_given?) # => true
|
16
|
+
MyNamespace.given?("some value") # => true
|
17
|
+
MyNamespace.given?(MyNamespace.not_given?) # => false
|
18
|
+
|
19
|
+
def my_method(value = MyNamespace.not_given)
|
20
|
+
if MyNamespace.given?(value)
|
21
|
+
# do something with the given value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def my_method(arg_value = MyNamespace.not_given)
|
26
|
+
value = MyNamespace.given?(value) ? value : "some default value"
|
27
|
+
|
28
|
+
# do something with the optionally defaulted value
|
29
|
+
end
|
30
|
+
```
|
8
31
|
|
9
32
|
## Installation
|
10
33
|
|
data/lib/much-not-given.rb
CHANGED
@@ -1,4 +1,51 @@
|
|
1
1
|
require "much-not-given/version"
|
2
|
+
require "much-plugin"
|
2
3
|
|
3
4
|
module MuchNotGiven
|
5
|
+
include MuchPlugin
|
6
|
+
|
7
|
+
plugin_class_methods do
|
8
|
+
def not_given
|
9
|
+
@not_given ||=
|
10
|
+
begin
|
11
|
+
Class.new {
|
12
|
+
def initialize(receiver_name)
|
13
|
+
@receiver_name = receiver_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def blank?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def present?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
"#{@receiver_name}.not_given"
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(other)
|
33
|
+
if other.is_a?(self.class)
|
34
|
+
true
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
}.new(self.inspect)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def not_given?(value)
|
44
|
+
value == not_given
|
45
|
+
end
|
46
|
+
|
47
|
+
def given?(value)
|
48
|
+
value != not_given
|
49
|
+
end
|
50
|
+
end
|
4
51
|
end
|
data/much-not-given.gemspec
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "assert"
|
2
|
+
require "much-not-given"
|
3
|
+
|
4
|
+
module MuchNotGiven
|
5
|
+
class UnitTests < Assert::Context
|
6
|
+
desc "MuchNotGiven"
|
7
|
+
subject { unit_module }
|
8
|
+
|
9
|
+
let(:unit_module) { MuchNotGiven }
|
10
|
+
|
11
|
+
should "inlcude MuchPlugin" do
|
12
|
+
assert_that(unit_module).includes(MuchPlugin)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ReceiverTests < UnitTests
|
17
|
+
desc "reciver"
|
18
|
+
subject { receiver_class }
|
19
|
+
|
20
|
+
let(:receiver_class) {
|
21
|
+
Class.new do
|
22
|
+
include MuchNotGiven
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
let(:value1) {
|
27
|
+
Factory.public_send(
|
28
|
+
[:integer, :string, :float, :data, :time, :path, :boolean].sample
|
29
|
+
)
|
30
|
+
}
|
31
|
+
|
32
|
+
should have_imeths :not_given, :not_given?, :given?
|
33
|
+
|
34
|
+
should "have a not_given singleton value" do
|
35
|
+
not_given = subject.not_given
|
36
|
+
|
37
|
+
assert_that(not_given.blank?).is_true
|
38
|
+
assert_that(not_given.present?).is_false
|
39
|
+
assert_that(not_given.to_s).equals("#{subject.inspect}.not_given")
|
40
|
+
assert_that(not_given.inspect).equals(not_given.to_s)
|
41
|
+
|
42
|
+
assert_that(subject.not_given).is_the_same_as(not_given)
|
43
|
+
assert_that(subject.not_given == not_given).is_true
|
44
|
+
assert_that(value1 == not_given).is_false
|
45
|
+
end
|
46
|
+
|
47
|
+
should "know if values are given or not" do
|
48
|
+
assert_that(subject.given?(value1)).is_true
|
49
|
+
assert_that(subject.given?(subject.not_given)).is_false
|
50
|
+
|
51
|
+
assert_that(subject.not_given?(value1)).is_false
|
52
|
+
assert_that(subject.not_given?(subject.not_given)).is_true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-not-given
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-12-
|
12
|
+
date: 2020-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: assert
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 2.18.4
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: much-plugin
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.2.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.2.2
|
28
42
|
description: Add "not given" default values to your objects.
|
29
43
|
email:
|
30
44
|
- kelly@kellyredding.com
|
@@ -44,6 +58,7 @@ files:
|
|
44
58
|
- test/support/factory.rb
|
45
59
|
- test/system/.keep
|
46
60
|
- test/unit/.keep
|
61
|
+
- test/unit/much-not-given_tests.rb
|
47
62
|
- tmp/.keep
|
48
63
|
homepage: https://github.com/redding/much-not-given
|
49
64
|
licenses:
|
@@ -73,3 +88,4 @@ test_files:
|
|
73
88
|
- test/support/factory.rb
|
74
89
|
- test/system/.keep
|
75
90
|
- test/unit/.keep
|
91
|
+
- test/unit/much-not-given_tests.rb
|