null_plus 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +60 -0
- data/Rakefile +30 -0
- data/lib/null_plus.rb +9 -0
- data/lib/null_plus/version.rb +4 -0
- data/null_plus.gemspec +22 -0
- data/spec/null_plus_spec.rb +23 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0bc61c208df3bca266a8bc9677559ed5be2b0a9f
|
4
|
+
data.tar.gz: 88420396cf11a45bb657d85065ad1d10f2848f6b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4a6a5609c0f37557dda3e980c4d8fa9e0487c9ec8f6dbc5dcc0f90683510c373e152ffa38534e8adba96cb4ddc879bd6c298f97218e30000910c3512f73c87f
|
7
|
+
data.tar.gz: 440a0e8997a8377b4ff163b3e861c31efc53197ce391807486c077a4c086b92e8a27da67af687b7e531fe94636ff83101f144939b98802b02e637e5af31e7e6f
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Jan Lelis, mail@janlelis.de
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# +nil [![[version]](https://badge.fury.io/rb/null_plus.svg)](http://badge.fury.io/rb/null_plus) [![[travis]](https://travis-ci.org/janlelis/null_plus.png)](https://travis-ci.org/janlelis/null_plus)
|
2
|
+
|
3
|
+
This gem redefines Ruby's unary `+` operator to turn null objects into nil. By default, the unary `+` operator is not used in Ruby, so overloading it is not so dangerous as it might have sound to you when you read it.
|
4
|
+
|
5
|
+
Every object that returns [true for `null?`](https://github.com/janlelis/null_question) is considered a null object.
|
6
|
+
|
7
|
+
|
8
|
+
## Setup
|
9
|
+
|
10
|
+
Add to your **Gemfile**:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "null_plus"
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class NullObject
|
21
|
+
def null?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
null = NullObject.new
|
27
|
+
|
28
|
+
+nil #=> nil
|
29
|
+
+null #=> nil
|
30
|
+
+"some object" #=> "some object"
|
31
|
+
|
32
|
+
# Useful for settings defaults or checking conditions:
|
33
|
+
if +null
|
34
|
+
fail # will not run
|
35
|
+
end
|
36
|
+
|
37
|
+
value = +null || 42 #=> 42
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
### Hint
|
42
|
+
|
43
|
+
Pay attention to proper operator precedence when chaining method class:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class NullObject
|
47
|
+
def null?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
null = NullObject.new
|
53
|
+
|
54
|
+
+null.class #=> NullObject
|
55
|
+
(+null).class #=> NilClass
|
56
|
+
```
|
57
|
+
|
58
|
+
## J-_-L
|
59
|
+
|
60
|
+
Copyright (C) 2015 Jan Lelis <http://janlelis.com>. Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# # #
|
2
|
+
# Get gemspec info
|
3
|
+
|
4
|
+
gemspec_file = Dir['*.gemspec'].first
|
5
|
+
gemspec = eval File.read(gemspec_file), binding, gemspec_file
|
6
|
+
info = "#{gemspec.name} | #{gemspec.version} | " \
|
7
|
+
"#{gemspec.runtime_dependencies.size} dependencies | " \
|
8
|
+
"#{gemspec.files.size} files"
|
9
|
+
|
10
|
+
|
11
|
+
# # #
|
12
|
+
# Gem build and install task
|
13
|
+
|
14
|
+
desc info
|
15
|
+
task :gem do
|
16
|
+
puts info + "\n\n"
|
17
|
+
print " "; sh "gem build #{gemspec_file}"
|
18
|
+
FileUtils.mkdir_p 'pkg'
|
19
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
20
|
+
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# # #
|
25
|
+
# Start an IRB session with the gem loaded
|
26
|
+
|
27
|
+
desc "#{gemspec.name} | IRB"
|
28
|
+
task :irb do
|
29
|
+
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
|
30
|
+
end
|
data/lib/null_plus.rb
ADDED
data/null_plus.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/lib/null_plus/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "null_plus"
|
7
|
+
gem.version = NullPlus::VERSION
|
8
|
+
gem.summary = "+nil"
|
9
|
+
gem.description = "This gem redefines Ruby's unary + operator to turn null objects into nil. By default, the unary + operator is not used by Ruby, so overloading it is not so dangerous as it might have sounded to you when you read it. Every object that returns true for null? is considered a null object."
|
10
|
+
gem.authors = ["Jan Lelis"]
|
11
|
+
gem.email = ["mail@janlelis.de"]
|
12
|
+
gem.homepage = "https://github.com/janlelis/null_plus"
|
13
|
+
gem.license = "MIT"
|
14
|
+
|
15
|
+
gem.files = Dir["{**/}{.*,*}"].select{ |path| File.file?(path) && path !~ /^pkg/ }
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.required_ruby_version = "~> 2.0"
|
21
|
+
gem.add_dependency "null_question", "~> 1.0"
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "../lib/null_plus"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
describe NullPlus do
|
5
|
+
describe "Object#+@" do
|
6
|
+
it "returns itself for non-null objects" do
|
7
|
+
object = Object.new
|
8
|
+
assert_equal object, +object
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns nil for nil" do
|
12
|
+
assert_equal nil, +nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil for custom null objects" do
|
16
|
+
null_object = Object.new
|
17
|
+
def null_object.null?() true end
|
18
|
+
assert_equal nil, +null_object
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: null_plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Lelis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: null_question
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: This gem redefines Ruby's unary + operator to turn null objects into
|
28
|
+
nil. By default, the unary + operator is not used by Ruby, so overloading it is
|
29
|
+
not so dangerous as it might have sounded to you when you read it. Every object
|
30
|
+
that returns true for null? is considered a null object.
|
31
|
+
email:
|
32
|
+
- mail@janlelis.de
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".gitignore"
|
38
|
+
- ".travis.yml"
|
39
|
+
- CHANGELOG.md
|
40
|
+
- Gemfile
|
41
|
+
- MIT-LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/null_plus.rb
|
45
|
+
- lib/null_plus/version.rb
|
46
|
+
- null_plus.gemspec
|
47
|
+
- spec/null_plus_spec.rb
|
48
|
+
homepage: https://github.com/janlelis/null_plus
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.4.6
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: "+nil"
|
72
|
+
test_files:
|
73
|
+
- spec/null_plus_spec.rb
|
74
|
+
has_rdoc:
|