boolean2 1.0.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 +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +34 -0
- data/Rakefile +43 -0
- data/boolean2.gemspec +21 -0
- data/lib/boolean2.rb +21 -0
- data/spec/boolean2_spec.rb +61 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a14f9de3abd91d441e3a023c5ba4ed4e3663e321
|
4
|
+
data.tar.gz: dbfe98e6fc57d3bd51c134ee406c46de88c76147
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9832163253f773cd6a5725e9edcdfc2e30129501322dc1254276cd9576d59bc460b4b03b8157b41a99cd606f5181f85e19d314c0be88127aa722cc092bf6b35a
|
7
|
+
data.tar.gz: b047e2c3ca6752698b607a0e20f922e6c490247c7330de4ee234c570a4227aec5294845ef8799c5b37d2486e84837525a818c48c96728002cea0cfeae586fc38
|
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,34 @@
|
|
1
|
+
# Boolean2 [![[version]](https://badge.fury.io/rb/boolean2.svg)](http://badge.fury.io/rb/boolean2) [![[travis]](https://travis-ci.org/janlelis/boolean2.png)](https://travis-ci.org/janlelis/boolean2)
|
2
|
+
|
3
|
+
Next time before you want to define a global `Boolean` class, consider using this bare-bones approach instead.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Add to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'boolean2'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
true.is_a? Boolean2 #=> true
|
17
|
+
false.is_a? Boolean2 #=> true
|
18
|
+
nil.is_a? Boolean2 #=> false
|
19
|
+
Object.new.is_a? Boolean2 #=> false
|
20
|
+
|
21
|
+
true.to_boolean2 #=> true
|
22
|
+
false.to_boolean2 #=> false
|
23
|
+
nil.to_boolean2 #=> false
|
24
|
+
Object.new.to_boolean2 #=> true
|
25
|
+
|
26
|
+
Boolean2.new(true) #=> true
|
27
|
+
Boolean2.new(false) #=> false
|
28
|
+
Boolean2.new(nil) #=> false
|
29
|
+
Boolean2.new(Object.new) #=> true
|
30
|
+
```
|
31
|
+
|
32
|
+
## J-_-L
|
33
|
+
|
34
|
+
Copyright (C) 2015 Jan Lelis <http://janlelis.com>. Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# # #
|
2
|
+
# Load gemspec info
|
3
|
+
gemspec_file = Dir['*.gemspec'].first
|
4
|
+
gemspec = eval File.read(gemspec_file), binding, gemspec_file
|
5
|
+
info = "#{gemspec.name} | #{gemspec.version} | " \
|
6
|
+
"#{gemspec.runtime_dependencies.size} dependencies | " \
|
7
|
+
"#{gemspec.files.size} files"
|
8
|
+
|
9
|
+
|
10
|
+
# # #
|
11
|
+
# Gem build and install task
|
12
|
+
desc info
|
13
|
+
task :gem do
|
14
|
+
puts info + "\n\n"
|
15
|
+
print " "; sh "gem build #{gemspec_file}"
|
16
|
+
FileUtils.mkdir_p 'pkg'
|
17
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
18
|
+
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# # #
|
23
|
+
# Start an IRB session with the gem loaded
|
24
|
+
|
25
|
+
desc "#{gemspec.name} | IRB"
|
26
|
+
task :irb do
|
27
|
+
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# # #
|
32
|
+
# Run the specs
|
33
|
+
|
34
|
+
desc "#{gemspec.name} | SPECS"
|
35
|
+
task :specs do
|
36
|
+
ruby "spec/*"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# # #
|
41
|
+
# Default
|
42
|
+
|
43
|
+
task default: :specs
|
data/boolean2.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/lib/boolean2"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "boolean2"
|
7
|
+
gem.version = Boolean2::VERSION
|
8
|
+
gem.summary = "A global Boolean2 constant that is an ancestor of true and false."
|
9
|
+
gem.description = "A global Boolean2 constant that is an ancestor of true and false. Useful for coercion libraries."
|
10
|
+
gem.authors = ["Jan Lelis"]
|
11
|
+
gem.email = "mail@janlelis.de"
|
12
|
+
gem.homepage = "https://github.com/janlelis/boolean2"
|
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
|
+
end
|
data/lib/boolean2.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Boolean2
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
|
4
|
+
def self.new(object)
|
5
|
+
object.to_boolean2
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TrueClass
|
10
|
+
include Boolean2
|
11
|
+
end
|
12
|
+
|
13
|
+
class FalseClass
|
14
|
+
include Boolean2
|
15
|
+
end
|
16
|
+
|
17
|
+
class Object
|
18
|
+
def to_boolean2
|
19
|
+
!!self
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative "../lib/boolean2"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
describe Boolean2 do
|
5
|
+
describe "true" do
|
6
|
+
it "is a Boolean2" do
|
7
|
+
assert_equal true, true.is_a?(Boolean2)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns itself for #to_boolean2" do
|
11
|
+
assert_equal true, true.to_boolean2
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns true when given to Boolean2.new" do
|
15
|
+
assert_equal true, Boolean2.new(true)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "false" do
|
20
|
+
it "is a Boolean2" do
|
21
|
+
assert_equal true, false.is_a?(Boolean2)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns itself for #to_boolean2" do
|
25
|
+
assert_equal false, false.to_boolean2
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false when given to Boolean2.new" do
|
29
|
+
assert_equal false, Boolean2.new(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "nil" do
|
34
|
+
it "is not a Boolean2" do
|
35
|
+
assert_equal false, nil.is_a?(Boolean2)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns false for #to_boolean2" do
|
39
|
+
assert_equal false, nil.to_boolean2
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns false when given to Boolean2.new" do
|
43
|
+
assert_equal false, Boolean2.new(nil)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "Object" do
|
48
|
+
it "is not a Boolean2" do
|
49
|
+
assert_equal false, Object.new.is_a?(Boolean2)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns true for #to_boolean2" do
|
53
|
+
assert_equal true, Object.new.to_boolean2
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns true when given to Boolean2.new" do
|
57
|
+
assert_equal true, Boolean2.new(Object.new)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boolean2
|
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-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A global Boolean2 constant that is an ancestor of true and false. Useful
|
14
|
+
for coercion libraries.
|
15
|
+
email: mail@janlelis.de
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- MIT-LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- boolean2.gemspec
|
28
|
+
- lib/boolean2.rb
|
29
|
+
- spec/boolean2_spec.rb
|
30
|
+
homepage: https://github.com/janlelis/boolean2
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.4.6
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: A global Boolean2 constant that is an ancestor of true and false.
|
54
|
+
test_files:
|
55
|
+
- spec/boolean2_spec.rb
|