exists 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 +18 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +34 -0
- data/Rakefile +30 -0
- data/exists.gemspec +22 -0
- data/lib/exists.rb +9 -0
- data/lib/exists/version.rb +4 -0
- data/spec/exists_spec.rb +22 -0
- metadata +70 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 14a3cfedfb4f098c6657d42d53c9a15c12dc1006
|
|
4
|
+
data.tar.gz: 434a0ed949d0b07f672f3003255c5b31e1659b25
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 03eff70d27c8c2b34f47bd7a7d5cf3b013b016bdb6353c310a9ed4f4e479ee700d5b8655fdf4ce29c759c67268dc9d008ef4d6099950144fc3efed3ad50e2d85
|
|
7
|
+
data.tar.gz: c5810e11e1ea83aeb4207f8c1393a869f4c1d8edeab8fa5ae945343aaf88b8422a5bd81c93037d05eb500dad1f7001011cabe0fa6d96926b05d7624f9c3e13c6
|
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
|
+
# exists [![[version]](https://badge.fury.io/rb/exists.svg)](http://badge.fury.io/rb/exists) [![[travis]](https://travis-ci.org/janlelis/exists.png)](https://travis-ci.org/janlelis/exists)
|
|
2
|
+
|
|
3
|
+
Like ActiveSupport's presence, but for [Object#null?](https://github.com/janlelis/null_question)
|
|
4
|
+
|
|
5
|
+
For example, this is useful when setting defaults via or: `object.exists || other_object`
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Setup
|
|
9
|
+
|
|
10
|
+
Add to your **Gemfile**:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem 'exists'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
class NullObject
|
|
21
|
+
def null?
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
nil.exists #=> nil
|
|
27
|
+
NullObject.new.exists #=> nil
|
|
28
|
+
"some object".exists #=> "some object"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## MIT License
|
|
33
|
+
|
|
34
|
+
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/exists.gemspec
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + "/lib/exists/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = "exists"
|
|
7
|
+
gem.version = Exists::VERSION
|
|
8
|
+
gem.summary = "Object#exists"
|
|
9
|
+
gem.description = "Objecd#exists: Like ActiveSupport's presence, but for Object#null?"
|
|
10
|
+
gem.authors = ["Jan Lelis"]
|
|
11
|
+
gem.email = "mail@janlelis.de"
|
|
12
|
+
gem.homepage = "https://github.com/janlelis/exists"
|
|
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
|
data/lib/exists.rb
ADDED
data/spec/exists_spec.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative "../lib/exists"
|
|
2
|
+
require "minitest/autorun"
|
|
3
|
+
|
|
4
|
+
describe Exists do
|
|
5
|
+
describe "Object#exists" do
|
|
6
|
+
it "returns itself for non-null objects" do
|
|
7
|
+
object = Object.new
|
|
8
|
+
assert_equal object, object.exists
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "returns nil for nil" do
|
|
12
|
+
assert_equal nil, nil.exists
|
|
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.exists
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: exists
|
|
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: 'Objecd#exists: Like ActiveSupport''s presence, but for Object#null?'
|
|
28
|
+
email: mail@janlelis.de
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- ".gitignore"
|
|
34
|
+
- ".travis.yml"
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- Gemfile
|
|
37
|
+
- MIT-LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- exists.gemspec
|
|
41
|
+
- lib/exists.rb
|
|
42
|
+
- lib/exists/version.rb
|
|
43
|
+
- spec/exists_spec.rb
|
|
44
|
+
homepage: https://github.com/janlelis/exists
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata: {}
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options: []
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - "~>"
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '2.0'
|
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
requirements: []
|
|
63
|
+
rubyforge_project:
|
|
64
|
+
rubygems_version: 2.4.6
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 4
|
|
67
|
+
summary: Object#exists
|
|
68
|
+
test_files:
|
|
69
|
+
- spec/exists_spec.rb
|
|
70
|
+
has_rdoc:
|