izzy 0.0.1
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +1 -0
- data/izzy.gemspec +22 -0
- data/lib/izzy/version.rb +3 -0
- data/lib/izzy.rb +17 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ea8cd88a3d1a4f422d1da5c6ff1e9bc188522f1
|
4
|
+
data.tar.gz: b774560935f6bbf5ee97dc993c4753bc2266f19e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3393d1c4776dd90f941de98e5b19f4fcba81c7a79a2b8eedcd5c819c2d24e3622952110effcff2533e9d9bfd4c69b2d0e312e944567440d8c4c5f67f93a99943
|
7
|
+
data.tar.gz: 28a25a641a3397a9ad4a5fac82e1de1df7c534326d74ca2ff487c6aaf9848afc371c69e0c6b7f80f38c7433795b95d3ffb003d8561ceaab6dea5c97870f5fe3c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Brandon Weaver
|
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,79 @@
|
|
1
|
+
# Izzy
|
2
|
+
|
3
|
+
Monkey patch to object to make for a nicer time of conditionals!
|
4
|
+
|
5
|
+
Let's take our class, Person:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class Person
|
9
|
+
def initialize(name, age, sex)
|
10
|
+
@name = name
|
11
|
+
@age = age
|
12
|
+
@sex = sex
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_older_than_18?
|
16
|
+
@age > 18
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_younger_than_18?
|
20
|
+
@age < 18
|
21
|
+
end
|
22
|
+
|
23
|
+
def is_male?
|
24
|
+
@sex == 'm'
|
25
|
+
end
|
26
|
+
|
27
|
+
def is_female?
|
28
|
+
@sex == 'f'
|
29
|
+
end
|
30
|
+
|
31
|
+
def is_me?
|
32
|
+
@name == 'brandon' && @sex == 'm'
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_geek?
|
36
|
+
@name == 'brandon'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
So we make our person:
|
42
|
+
```ruby
|
43
|
+
brandon = Person.new('brandon', 23, 'm')
|
44
|
+
```
|
45
|
+
|
46
|
+
...and do some comparisons!
|
47
|
+
```ruby
|
48
|
+
brandon.is_all_of(:older_than_18, :male, :me, :geek) # => true
|
49
|
+
brandon.is_none_of(:younger_than_18, :female) # => true
|
50
|
+
brandon.is_any_of(:male, :female, :geek) # => true
|
51
|
+
```
|
52
|
+
|
53
|
+
Simple to the point, no more mess of && or || checks for the same object.
|
54
|
+
|
55
|
+
## Installation
|
56
|
+
|
57
|
+
Add this line to your application's Gemfile:
|
58
|
+
|
59
|
+
gem 'izzy'
|
60
|
+
|
61
|
+
And then execute:
|
62
|
+
|
63
|
+
$ bundle
|
64
|
+
|
65
|
+
Or install it yourself as:
|
66
|
+
|
67
|
+
$ gem install izzy
|
68
|
+
|
69
|
+
## Usage
|
70
|
+
|
71
|
+
It patches object, just use it with any method that matches the pattern is_foo? and you're good to go!
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it ( http://github.com/<my-github-username>/izzy/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/izzy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'izzy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "izzy"
|
8
|
+
spec.version = Izzy::VERSION
|
9
|
+
spec.authors = ["Brandon Weaver"]
|
10
|
+
spec.email = ["keystonelemur@gmail.com"]
|
11
|
+
spec.summary = %q{Gives you methods to mitigate long conditionals}
|
12
|
+
spec.homepage = "http://www.github.com/baweaver/izzy"
|
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{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/lib/izzy/version.rb
ADDED
data/lib/izzy.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "izzy/version"
|
2
|
+
|
3
|
+
class Object
|
4
|
+
METHOD_CHECK = -> method { "is_#{method}?".to_sym.tap { |m| self.respond_to?(m) && self.send(m) }}
|
5
|
+
|
6
|
+
def is_all_of(*methods)
|
7
|
+
methods.all?(&METHOD_CHECK)
|
8
|
+
end
|
9
|
+
|
10
|
+
def is_any_of(*methods)
|
11
|
+
methods.any?(&METHOD_CHECK)
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_none_of(*methods)
|
15
|
+
methods.none?(&METHOD_CHECK)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: izzy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Weaver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- keystonelemur@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- izzy.gemspec
|
54
|
+
- lib/izzy.rb
|
55
|
+
- lib/izzy/version.rb
|
56
|
+
homepage: http://www.github.com/baweaver/izzy
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.1.10
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Gives you methods to mitigate long conditionals
|
80
|
+
test_files: []
|