trueman 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +7 -0
- data/lib/trueman.rb +34 -0
- data/lib/trueman/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/trueman_spec.rb +39 -0
- data/trueman.gemspec +23 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2c6c53a6723d60bff885306f132ca1ea85c02c5
|
4
|
+
data.tar.gz: 91a5d949426a4ef28bf326e1ac936560e0f6106d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f12fec59fdd50dd52d2c68caa47ddf59ec160692a228a2c7ac80c884bb6c80d1f2d25371c35323beec167c6112a97d48463e9ee12513b90401345ea29c90de06
|
7
|
+
data.tar.gz: 4ccc77e190042500e54557891957c0cd4a75e3d6b511960ea821fd86e79564d09d58d5e6170bdfe977a5c30238434aae03458dba0e5a23cbc0cfa540b283943f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Rob Head
|
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
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Trueman
|
2
|
+
|
3
|
+
*Introducing: The World's (Almost) Smallest RubyGem*
|
4
|
+
|
5
|
+
Assert if a value matches one of the common forms of true or false with
|
6
|
+
this little (ruby)gem :)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'trueman'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Trueman is designed to assert if a value is true. It does not test for
|
23
|
+
`presence` of a value, just that it matches one of the following items:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Trueman.truthy? 1 # => true
|
27
|
+
Trueman.truthy? "t" # => true
|
28
|
+
Trueman.truthy? "T" # => true
|
29
|
+
Trueman.truthy? true # => true
|
30
|
+
Trueman.truthy? "true" # => true
|
31
|
+
Trueman.truthy? "TRUE" # => true
|
32
|
+
|
33
|
+
Trueman.falsy? 0 # => true
|
34
|
+
Trueman.falsy? "f" # => true
|
35
|
+
Trueman.falsy? "F" # => true
|
36
|
+
Trueman.falsy? false # => true
|
37
|
+
Trueman.falsy? "false" # => true
|
38
|
+
Trueman.falsy? "FALSE" # => true
|
39
|
+
```
|
40
|
+
|
41
|
+
If this list is not enough, you can easily add to the list:
|
42
|
+
```ruby
|
43
|
+
Trueman.true_values << "foo"
|
44
|
+
Trueman.false_values << "bar"
|
45
|
+
|
46
|
+
Trueman.truthy? "foo" # => true
|
47
|
+
Trueman.falsy? "bar" # => true
|
48
|
+
```
|
49
|
+
|
50
|
+
Both `true_values` and `false_values` exposes a class level array. That
|
51
|
+
means you can remove values, expose values or do anything else you can
|
52
|
+
do on an enumerable array.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Trueman.true_values # => [1,'t','T',true,'true','TRUE']
|
56
|
+
```
|
57
|
+
|
58
|
+
Although it's discouraged, you can patch `Object`:
|
59
|
+
```ruby
|
60
|
+
Trueman.patch_object!
|
61
|
+
|
62
|
+
"true".truthy? # => true
|
63
|
+
1.truthy? # => true
|
64
|
+
0.falsy? # => true
|
65
|
+
# ...
|
66
|
+
```
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it ( https://github.com/[my-github-username]/trueman/fork )
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/trueman.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "trueman/version"
|
2
|
+
|
3
|
+
module Trueman
|
4
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
5
|
+
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE']
|
6
|
+
|
7
|
+
def self.truthy?(value)
|
8
|
+
true_values.include? value
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.falsy?(value)
|
12
|
+
false_values.include? value
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.true_values
|
16
|
+
@@true_values ||= TRUE_VALUES
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.false_values
|
20
|
+
@@false_values ||= FALSE_VALUES
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.patch_object!
|
24
|
+
Object.class_eval do
|
25
|
+
def truthy?
|
26
|
+
Trueman.truthy? self
|
27
|
+
end unless self.class.respond_to?(:truthy?)
|
28
|
+
|
29
|
+
def falsy?
|
30
|
+
Trueman.falsy? self
|
31
|
+
end unless self.class.respond_to?(:falsy?)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Trueman do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(Trueman::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'updating truthy values' do
|
9
|
+
before { Trueman.true_values << 'foo' }
|
10
|
+
|
11
|
+
it "allows a new value" do
|
12
|
+
expect(Trueman.truthy?('foo')).to eq true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'updating falsy values' do
|
17
|
+
before { Trueman.false_values << 'bar' }
|
18
|
+
|
19
|
+
it "allows a new value" do
|
20
|
+
expect(Trueman.truthy?('bar')).to eq false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'determine a falsy value' do
|
25
|
+
[0, false, "false", "FALSE", "f", "F"].each do |value|
|
26
|
+
it "returns true for the value #{value}" do
|
27
|
+
expect(Trueman.falsy?(value)).to eq true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'determine a truthy value' do
|
33
|
+
[1, true, "true", "TRUE", "t", "T"].each do |value|
|
34
|
+
it "returns true for the value #{value}" do
|
35
|
+
expect(Trueman.truthy?(value)).to eq true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/trueman.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trueman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "trueman"
|
8
|
+
spec.version = Trueman::VERSION
|
9
|
+
spec.authors = ["Sean Culver", "Adam Cuppy"]
|
10
|
+
spec.email = ["sean@codingzeal.com", "adam@codingzeal.com"]
|
11
|
+
spec.summary = %q{Easily assert truthy and falsy values on strings integers}
|
12
|
+
spec.homepage = "https://github.com/CodingZeal/trueman"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trueman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Culver
|
8
|
+
- Adam Cuppy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.6'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.1.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.1.0
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- sean@codingzeal.com
|
59
|
+
- adam@codingzeal.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/trueman.rb
|
72
|
+
- lib/trueman/version.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/trueman_spec.rb
|
75
|
+
- trueman.gemspec
|
76
|
+
homepage: https://github.com/CodingZeal/trueman
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Easily assert truthy and falsy values on strings integers
|
100
|
+
test_files:
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/trueman_spec.rb
|