null_and_void 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +22 -0
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/lib/null_and_void/convertible.rb +5 -5
- data/lib/null_and_void/inflections.rb +7 -3
- data/lib/null_and_void/model_support.rb +2 -2
- data/lib/null_and_void/stubbable.rb +1 -1
- data/lib/null_and_void/version.rb +1 -1
- data/spec/convertible_spec.rb +23 -21
- data/spec/falsifiable_spec.rb +6 -4
- data/spec/introspectable_spec.rb +2 -2
- data/spec/maybe_spec.rb +2 -2
- data/spec/model_support_spec.rb +6 -4
- data/spec/null_and_void_spec.rb +1 -1
- data/spec/null_object_spec.rb +3 -3
- data/spec/nullified_spec.rb +6 -4
- data/spec/stubbable_spec.rb +1 -1
- metadata +11 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0654e5f58b7aff4685fe3987c117b6d4534e9dfb
|
4
|
+
data.tar.gz: d41982e1fdbecf212796ede8842f2826a59ba8ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c113841029277cb3c5edb8e3dea85618173d3e29ac86fa791263beebdbbdf0f52e4209868444b342cb0fc72e07af681c3da0fc304121188f63309f787df83d8e
|
7
|
+
data.tar.gz: b86c5b629f33e49577e193afba301f9e1cd2847acc207629a9a8d214ddabadbfbfed27ea794c6b0c96a2f77221b0f961800fba1833f7215d312471429afd848a
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jeff Felchner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Null And Void
|
2
2
|
================================
|
3
3
|
|
4
|
+
[![Build Status](https://secure.travis-ci.org/jfelchner/null_and_void.png?branch=master)](http://travis-ci.org/jfelchner/null_and_void) [![Code Climate](https://codeclimate.com/github/jfelchner/null_and_void.png)](https://codeclimate.com/github/jfelchner/null_and_void) [![Code Climate](https://codeclimate.com/github/jfelchner/null_and_void/coverage.png)](https://codeclimate.com/github/jfelchner/null_and_void)
|
5
|
+
|
4
6
|
**Create Null Objects with Ease**
|
5
7
|
|
6
8
|
<img src="https://dl.dropbox.com/s/3vro4yd2vsa5xga/bad-luck-brian-null-object.jpg" align="right" />
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -10,13 +10,13 @@ module NullAndVoid
|
|
10
10
|
Complex(0)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
alias_method :to_int, :to_i
|
14
14
|
|
15
15
|
def to_f
|
16
16
|
0.0
|
17
17
|
end
|
18
18
|
|
19
|
-
def rationalize(*
|
19
|
+
def rationalize(*_args)
|
20
20
|
Rational(0)
|
21
21
|
end
|
22
22
|
|
@@ -25,13 +25,13 @@ module NullAndVoid
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def to_a
|
28
|
-
|
28
|
+
[]
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
alias_method :to_ary, :to_a
|
32
32
|
|
33
33
|
def to_hash
|
34
|
-
|
34
|
+
{}
|
35
35
|
end
|
36
36
|
|
37
37
|
def to_html
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# rubocop:disable Lint/AssignmentInCondition, Metrics/CyclomaticComplexity
|
2
|
+
# rubocop:disable Metrics/LineLength, Metrics/PerceivedComplexity, Style/EachWithObject
|
1
3
|
module NullAndVoid
|
2
4
|
module Inflections
|
3
5
|
def self.demodulize(path)
|
4
6
|
path = path.to_s
|
5
7
|
if i = path.rindex('::')
|
6
|
-
path[(i+2)..-1]
|
8
|
+
path[(i + 2)..-1]
|
7
9
|
else
|
8
10
|
path
|
9
11
|
end
|
@@ -22,7 +24,7 @@ module Inflections
|
|
22
24
|
# Remove the first blank element in case of '::ClassName' notation.
|
23
25
|
names.shift if names.size > 1 && names.first.empty?
|
24
26
|
|
25
|
-
names.
|
27
|
+
names.reduce(Object) do |constant, name|
|
26
28
|
if constant == Object
|
27
29
|
constant.const_get(name)
|
28
30
|
else
|
@@ -32,7 +34,7 @@ module Inflections
|
|
32
34
|
|
33
35
|
# Go down the ancestors to check it it's owned
|
34
36
|
# directly before we reach Object or the end of ancestors.
|
35
|
-
constant = constant.ancestors.
|
37
|
+
constant = constant.ancestors.reduce do |const, ancestor|
|
36
38
|
break const if ancestor == Object
|
37
39
|
break ancestor if ancestor.const_defined?(name, false)
|
38
40
|
const
|
@@ -45,3 +47,5 @@ module Inflections
|
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
50
|
+
# rubocop:enable Lint/AssignmentInCondition, Metrics/CyclomaticComplexity
|
51
|
+
# rubocop:enable Metrics/LineLength, Metrics/PerceivedComplexity, Style/EachWithObject
|
@@ -5,8 +5,8 @@ module NullAndVoid
|
|
5
5
|
module ModelSupport
|
6
6
|
module ClassMethods
|
7
7
|
def as_null_object
|
8
|
-
base_path = NullAndVoid::Inflections.demodulize(
|
9
|
-
module_path = NullAndVoid::Inflections.deconstantize(
|
8
|
+
base_path = NullAndVoid::Inflections.demodulize(name)
|
9
|
+
module_path = NullAndVoid::Inflections.deconstantize(name)
|
10
10
|
null_object_base = "Null#{base_path}"
|
11
11
|
source_model_path = "#{module_path}::#{null_object_base}"
|
12
12
|
|
data/spec/convertible_spec.rb
CHANGED
@@ -18,58 +18,60 @@ describe NullAndVoid::Convertible do
|
|
18
18
|
let(:null_object) { FooBar::NullObject.new }
|
19
19
|
|
20
20
|
it 'is zero when the attempt is made to convert it to an Integer' do
|
21
|
-
null_object.to_i.
|
22
|
-
null_object.to_i.
|
21
|
+
expect(null_object.to_i).to be_an Integer
|
22
|
+
expect(null_object.to_i).to be_zero
|
23
23
|
|
24
|
-
null_object.to_int.
|
25
|
-
null_object.to_int.
|
24
|
+
expect(null_object.to_int).to be_an Integer
|
25
|
+
expect(null_object.to_int).to be_zero
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'is zero when the attempt is made to convert it to a Complex number' do
|
29
|
-
null_object.to_c.
|
30
|
-
null_object.to_c.
|
29
|
+
expect(null_object.to_c).to be_a Complex
|
30
|
+
expect(null_object.to_c).to be_zero
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'is zero when the attempt is made to convert it to a Float' do
|
34
|
-
null_object.to_f.
|
35
|
-
null_object.to_f.
|
34
|
+
expect(null_object.to_f).to be_a Float
|
35
|
+
expect(null_object.to_f).to be_zero
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'is zero when the attempt is made to convert it to a Rational' do
|
39
|
-
null_object.to_r.
|
40
|
-
null_object.to_r.
|
39
|
+
expect(null_object.to_r).to be_a Rational
|
40
|
+
expect(null_object.to_r).to be_zero
|
41
41
|
|
42
|
-
null_object.rationalize.
|
43
|
-
null_object.rationalize.
|
42
|
+
expect(null_object.rationalize).to be_a Rational
|
43
|
+
expect(null_object.rationalize).to be_zero
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'is an empty Array when the attempt is made to convert it to an Array' do
|
47
|
-
null_object.to_a.
|
48
|
-
null_object.to_ary.
|
47
|
+
expect(null_object.to_a).to eql []
|
48
|
+
expect(null_object.to_ary).to eql []
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'is an empty Hash when the attempt is made to convert it to an Hash' do
|
52
|
-
null_object.to_hash.
|
52
|
+
expect(null_object.to_hash).to eql({})
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'is an empty String when the attempt is made to convert it to HTML' do
|
56
|
-
null_object.to_html.
|
56
|
+
expect(null_object.to_html).to eql ''
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'is an empty String when the attempt is made to convert it to JSON' do
|
60
|
-
null_object.to_json.
|
60
|
+
expect(null_object.to_json).to eql 'null'
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'is an empty String when the attempt is made to convert it to XML' do
|
64
|
-
null_object.to_xml.
|
64
|
+
expect(null_object.to_xml).to eql ''
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'is an empty String when the attempt is made to convert it to a String' do
|
68
|
-
null_object.to_s.
|
68
|
+
expect(null_object.to_s).to eql ''
|
69
69
|
end
|
70
70
|
|
71
|
-
it 'is the class the Null Object is based on when the attempt is made to convert
|
72
|
-
|
71
|
+
it 'is the class the Null Object is based on when the attempt is made to convert ' \
|
72
|
+
'it to a value object' do
|
73
|
+
|
74
|
+
expect(null_object.to_model).to be_a FooBar::Object
|
73
75
|
end
|
74
76
|
|
75
77
|
it 'raises an error if the model the Null Object is based on does not exist' do
|
data/spec/falsifiable_spec.rb
CHANGED
@@ -8,19 +8,21 @@ end
|
|
8
8
|
describe NullAndVoid::Falsifiable do
|
9
9
|
let(:null_object) { NullObject.new }
|
10
10
|
|
11
|
+
# rubocop:disable Style/DoubleNegation
|
11
12
|
it 'can be double inverted to be false' do
|
12
|
-
(!!null_object).
|
13
|
+
expect(!!null_object).to eql false
|
13
14
|
end
|
15
|
+
# rubocop:enable Style/DoubleNegation
|
14
16
|
|
15
17
|
it 'is blank' do
|
16
|
-
null_object.
|
18
|
+
expect(null_object).to be_blank
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'is nil' do
|
20
|
-
null_object.
|
22
|
+
expect(null_object).to be_nil
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'is not present' do
|
24
|
-
null_object.
|
26
|
+
expect(null_object).not_to be_present
|
25
27
|
end
|
26
28
|
end
|
data/spec/introspectable_spec.rb
CHANGED
@@ -9,10 +9,10 @@ describe NullAndVoid::Introspectable do
|
|
9
9
|
let(:null_object) { MyNullObject.new }
|
10
10
|
|
11
11
|
it 'knows it is a null object' do
|
12
|
-
null_object.
|
12
|
+
expect(null_object).to be_null_object
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'can inspect itself' do
|
16
|
-
null_object.inspect.
|
16
|
+
expect(null_object.inspect).to match(/\A#<MyNullObject:0x[a-f0-9]{4,12}>\z/)
|
17
17
|
end
|
18
18
|
end
|
data/spec/maybe_spec.rb
CHANGED
@@ -8,13 +8,13 @@ end
|
|
8
8
|
describe NullAndVoid::Maybe do
|
9
9
|
context 'when it is passed a nil' do
|
10
10
|
it 'is a null object' do
|
11
|
-
MyObject.new.maybe(nil).
|
11
|
+
expect(MyObject.new.maybe(nil)).to be_a NullAndVoid::NullObject
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when it is passed something other than nil' do
|
16
16
|
it 'is the non-nil object' do
|
17
|
-
MyObject.new.maybe(1).
|
17
|
+
expect(MyObject.new.maybe(1)).to eql 1
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/spec/model_support_spec.rb
CHANGED
@@ -19,14 +19,16 @@ describe NullAndVoid::ModelSupport do
|
|
19
19
|
let(:model) { FooBar::MyNullableModel.new }
|
20
20
|
|
21
21
|
it 'can convert a model into its Null Object if it exists' do
|
22
|
-
model.as_null_object.
|
22
|
+
expect(model.as_null_object).to be_a FooBar::NullMyNullableModel
|
23
23
|
end
|
24
24
|
|
25
25
|
it "can convert the model's class into its Null Object if it exists" do
|
26
|
-
model.class.as_null_object.
|
26
|
+
expect(model.class.as_null_object).to be_a FooBar::NullMyNullableModel
|
27
27
|
end
|
28
28
|
|
29
|
-
it 'can convert a model into a generic Null Object a model-specific Null Object
|
30
|
-
|
29
|
+
it 'can convert a model into a generic Null Object a model-specific Null Object ' \
|
30
|
+
'does not exist' do
|
31
|
+
|
32
|
+
expect(NonNullableModel.as_null_object).to be_a NullAndVoid::NullObject
|
31
33
|
end
|
32
34
|
end
|
data/spec/null_and_void_spec.rb
CHANGED
data/spec/null_object_spec.rb
CHANGED
@@ -9,14 +9,14 @@ describe NullAndVoid::NullObject do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'is stubbable' do
|
12
|
-
null_object.
|
12
|
+
expect(null_object).to be_a NullAndVoid::Stubbable
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'is convertible' do
|
16
|
-
null_object.
|
16
|
+
expect(null_object).to be_a NullAndVoid::Convertible
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'is falsifiable' do
|
20
|
-
null_object.
|
20
|
+
expect(null_object).to be_a NullAndVoid::Falsifiable
|
21
21
|
end
|
22
22
|
end
|
data/spec/nullified_spec.rb
CHANGED
@@ -22,18 +22,20 @@ describe NullAndVoid::Nullified do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'handles undefined methods' do
|
25
|
-
null_object.foobar.
|
25
|
+
expect(null_object.foobar).to eql NullWidget.instance
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'handles conversions' do
|
29
|
-
null_object.to_a.
|
29
|
+
expect(null_object.to_a).to eql []
|
30
30
|
end
|
31
31
|
|
32
|
+
# rubocop:disable Style/DoubleNegation
|
32
33
|
it 'is falsifiable' do
|
33
|
-
(!!null_object).
|
34
|
+
expect(!!null_object).to eql false
|
34
35
|
end
|
36
|
+
# rubocop:enable Style/DoubleNegation
|
35
37
|
|
36
38
|
it 'can implement its own methods' do
|
37
|
-
null_object.my_null_object_method.
|
39
|
+
expect(null_object.my_null_object_method).to eql 'i am null'
|
38
40
|
end
|
39
41
|
end
|
data/spec/stubbable_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: null_and_void
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,35 +16,35 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.1'
|
20
20
|
type: :development
|
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: '
|
26
|
+
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspectacular
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.21.6
|
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.21.6
|
41
41
|
description: Makes generating Null Objects easy.
|
42
42
|
email: accounts+git@thekompanee.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
|
-
extra_rdoc_files:
|
46
|
-
- README.md
|
45
|
+
extra_rdoc_files: []
|
47
46
|
files:
|
47
|
+
- LICENSE
|
48
48
|
- README.md
|
49
49
|
- Rakefile
|
50
50
|
- lib/null_and_void.rb
|
@@ -71,8 +71,7 @@ homepage: https://github.com/jfelchner/null_and_void
|
|
71
71
|
licenses: []
|
72
72
|
metadata: {}
|
73
73
|
post_install_message:
|
74
|
-
rdoc_options:
|
75
|
-
- "--charset = UTF-8"
|
74
|
+
rdoc_options: []
|
76
75
|
require_paths:
|
77
76
|
- lib
|
78
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -86,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
85
|
- !ruby/object:Gem::Version
|
87
86
|
version: '0'
|
88
87
|
requirements: []
|
89
|
-
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.6
|
91
90
|
signing_key:
|
92
91
|
specification_version: 4
|
93
92
|
summary: Easy Null Objects
|
@@ -101,4 +100,3 @@ test_files:
|
|
101
100
|
- spec/null_object_spec.rb
|
102
101
|
- spec/nullified_spec.rb
|
103
102
|
- spec/stubbable_spec.rb
|
104
|
-
has_rdoc:
|