oror 0.1.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/.document +5 -0
- data/.editorconfig +38 -0
- data/.rspec +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +20 -0
- data/README.md +37 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/oror.rb +30 -0
- data/oror.gemspec +61 -0
- data/spec/oror_spec.rb +18 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9174e898cb0cf6d95555783cfa0b903a3213436c
|
4
|
+
data.tar.gz: 6fc266b09c56fe6c9a60ce4490d70e880d87b4e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0fce037b8659a0388c8850c424c1e36973c729a14fef52126ae83f54fb6a6363e613f93ad5eb88f3b16c14960509e59b814b40cb033cf0350b47386ad06ad0b0
|
7
|
+
data.tar.gz: 3e821d0efa4b13804e6f8edfa1eb4a4686377b6a74a1764afdd1edb95034618727ddec539dc86ecc15941aa1c19847a7abf964781872ed25dab147ecee78a152
|
data/.document
ADDED
data/.editorconfig
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# editorconfig.org
|
2
|
+
|
3
|
+
root = true
|
4
|
+
|
5
|
+
[*]
|
6
|
+
indent_style = space
|
7
|
+
end_of_line = lf
|
8
|
+
charset = utf-8
|
9
|
+
trim_trailing_whitespace = true
|
10
|
+
insert_final_newline = true
|
11
|
+
|
12
|
+
[*.rb]
|
13
|
+
indent_style = space
|
14
|
+
|
15
|
+
[*.erb]
|
16
|
+
indent_style = space
|
17
|
+
indent_size = 2
|
18
|
+
|
19
|
+
[*.rake]
|
20
|
+
indent_style = space
|
21
|
+
indent_size = 2
|
22
|
+
|
23
|
+
[*.haml]
|
24
|
+
indent_style = space
|
25
|
+
|
26
|
+
[*.html]
|
27
|
+
indent_style = space
|
28
|
+
indent_size = 2
|
29
|
+
|
30
|
+
[*.css]
|
31
|
+
indent_size = 2
|
32
|
+
|
33
|
+
[*.less]
|
34
|
+
indent_size = 2
|
35
|
+
|
36
|
+
[*.coffee]
|
37
|
+
indent_size = 2
|
38
|
+
indent_style = space
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format=doc --color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.4.0)
|
5
|
+
builder (3.2.2)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
8
|
+
docile (1.1.5)
|
9
|
+
faraday (0.9.2)
|
10
|
+
multipart-post (>= 1.2, < 3)
|
11
|
+
git (1.3.0)
|
12
|
+
github_api (0.13.1)
|
13
|
+
addressable (~> 2.4.0)
|
14
|
+
descendants_tracker (~> 0.0.4)
|
15
|
+
faraday (~> 0.8, < 0.10)
|
16
|
+
hashie (>= 3.4)
|
17
|
+
multi_json (>= 1.7.5, < 2.0)
|
18
|
+
oauth2
|
19
|
+
hashie (3.4.3)
|
20
|
+
highline (1.7.8)
|
21
|
+
jeweler (2.0.1)
|
22
|
+
builder
|
23
|
+
bundler (>= 1.0)
|
24
|
+
git (>= 1.2.5)
|
25
|
+
github_api
|
26
|
+
highline (>= 1.6.15)
|
27
|
+
nokogiri (>= 1.5.10)
|
28
|
+
rake
|
29
|
+
rdoc
|
30
|
+
json (1.8.3)
|
31
|
+
jwt (1.5.1)
|
32
|
+
mini_portile2 (2.0.0)
|
33
|
+
multi_json (1.11.2)
|
34
|
+
multi_xml (0.5.5)
|
35
|
+
multipart-post (2.0.0)
|
36
|
+
nokogiri (1.6.7.2)
|
37
|
+
mini_portile2 (~> 2.0.0.rc2)
|
38
|
+
oauth2 (1.1.0)
|
39
|
+
faraday (>= 0.8, < 0.10)
|
40
|
+
jwt (~> 1.0, < 1.5.2)
|
41
|
+
multi_json (~> 1.3)
|
42
|
+
multi_xml (~> 0.5)
|
43
|
+
rack (>= 1.2, < 3)
|
44
|
+
rack (1.6.4)
|
45
|
+
rake (11.0.1)
|
46
|
+
rdoc (4.2.2)
|
47
|
+
json (~> 1.4)
|
48
|
+
rspec (0.9.4)
|
49
|
+
simplecov (0.11.2)
|
50
|
+
docile (~> 1.1.0)
|
51
|
+
json (~> 1.8)
|
52
|
+
simplecov-html (~> 0.10.0)
|
53
|
+
simplecov-html (0.10.0)
|
54
|
+
thread_safe (0.3.5)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bundler (~> 1.0)
|
61
|
+
jeweler (~> 2.0.1)
|
62
|
+
rspec (~> 0)
|
63
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Juraj Masar
|
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,37 @@
|
|
1
|
+
# Object#oror gem
|
2
|
+
|
3
|
+
Inspired by the awesome [andand gem](https://github.com/raganwald/andand).
|
4
|
+
|
5
|
+
`||` operator works just fine in most of the cases:
|
6
|
+
|
7
|
+
```
|
8
|
+
false || 'alternative' == 'alternative'
|
9
|
+
nil || 'alternative' == 'alternative'
|
10
|
+
```
|
11
|
+
|
12
|
+
However, sometimes you might wish for a different behavior:
|
13
|
+
|
14
|
+
```
|
15
|
+
'' || 'alternative' == ''
|
16
|
+
"\t\n\r" || 'alternative == "\t\n\r"
|
17
|
+
```
|
18
|
+
|
19
|
+
That's where **oror** comes in:
|
20
|
+
|
21
|
+
```
|
22
|
+
false.oror 'alternative' == 'alternative'
|
23
|
+
nil.oror 'alternative' == 'alternative'
|
24
|
+
''.oror 'alternative' == 'alternative'
|
25
|
+
"\t\n\r".oror 'alternative == 'alternative'
|
26
|
+
```
|
27
|
+
|
28
|
+
No more `value.present? ? value : 'alternative'`.
|
29
|
+
|
30
|
+
# Installation
|
31
|
+
|
32
|
+
* Run `gem install oror`
|
33
|
+
* or add `gem 'oror'` into your `Gemfile` and run `bundle install`
|
34
|
+
|
35
|
+
# License
|
36
|
+
|
37
|
+
Released under MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "oror"
|
18
|
+
gem.homepage = "http://github.com/jurajmasar/oror"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Alternative || operator}
|
21
|
+
gem.description = %Q{Get rid of value.present? ? value : alternative}
|
22
|
+
gem.email = "mail@jurajmasar.com"
|
23
|
+
gem.authors = ["Juraj Masar"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "oror #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/oror.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# from https://github.com/rails/rails/blob/42b0c942520e59399d70c2170253aa5275a42af1/activesupport/lib/active_support/core_ext/object/blank.rb#L115
|
2
|
+
class String
|
3
|
+
BLANK_RE = /\A[[:space:]]*\z/
|
4
|
+
|
5
|
+
# A string is blank if it's empty or contains whitespaces only:
|
6
|
+
#
|
7
|
+
# ''.blank? # => true
|
8
|
+
# ' '.blank? # => true
|
9
|
+
# "\t\n\r".blank? # => true
|
10
|
+
# ' blah '.blank? # => false
|
11
|
+
#
|
12
|
+
# Unicode whitespace is supported:
|
13
|
+
#
|
14
|
+
# "\u00a0".blank? # => true
|
15
|
+
#
|
16
|
+
# @return [true, false]
|
17
|
+
def blank?
|
18
|
+
BLANK_RE === self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Object
|
23
|
+
def oror(alternative)
|
24
|
+
if respond_to?(:blank?) && !!blank? || respond_to?(:empty?) && !!empty? || !self
|
25
|
+
alternative
|
26
|
+
else
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/oror.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: oror 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "oror"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Juraj Masar"]
|
14
|
+
s.date = "2016-03-10"
|
15
|
+
s.description = "Get rid of value.present? ? value : alternative"
|
16
|
+
s.email = "mail@jurajmasar.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".editorconfig",
|
24
|
+
".rspec",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.md",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"lib/oror.rb",
|
32
|
+
"oror.gemspec",
|
33
|
+
"spec/oror_spec.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/jurajmasar/oror"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.rubygems_version = "2.4.5"
|
38
|
+
s.summary = "Alternative || operator"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 4
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<rspec>, ["~> 0"])
|
45
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
47
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rspec>, ["~> 0"])
|
50
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
51
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
52
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
58
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/spec/oror_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../lib/oror'
|
2
|
+
|
3
|
+
describe 'oror' do
|
4
|
+
shared_examples_for 'oror' do |object, alternative, result|
|
5
|
+
it "#{object}.oror #{alternative} == #{result}" do
|
6
|
+
expect(object.oror alternative).to eq result
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it_behaves_like 'oror', 47, 48, 47
|
11
|
+
it_behaves_like 'oror', '', 'alternative', 'alternative'
|
12
|
+
it_behaves_like 'oror', nil, 'alternative', 'alternative'
|
13
|
+
it_behaves_like 'oror', false, 'alternative', 'alternative'
|
14
|
+
it_behaves_like 'oror', ' ', 'alternative', 'alternative'
|
15
|
+
it_behaves_like 'oror', true, 'alternative', true
|
16
|
+
it_behaves_like 'oror', 47.47, 'alternative', 47.47
|
17
|
+
it_behaves_like 'oror', "\t\n\r", 'alternative', 'alternative'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oror
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juraj Masar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jeweler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: 'Get rid of value.present? ? value : alternative'
|
70
|
+
email: mail@jurajmasar.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
files:
|
77
|
+
- ".document"
|
78
|
+
- ".editorconfig"
|
79
|
+
- ".rspec"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
86
|
+
- lib/oror.rb
|
87
|
+
- oror.gemspec
|
88
|
+
- spec/oror_spec.rb
|
89
|
+
homepage: http://github.com/jurajmasar/oror
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Alternative || operator
|
113
|
+
test_files: []
|