izzy 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc28143ae2179e8bd4ff348fa131d241535184fc
4
- data.tar.gz: ae6e5e1126ff074a2b0644472f3fd66e645cfa1f
3
+ metadata.gz: 92ef9a7d5d309a6a3396ee667f2a70a0147d8fb0
4
+ data.tar.gz: b9740f151081e14ccd682eaf61ad33303839ca83
5
5
  SHA512:
6
- metadata.gz: 49dc4b9dab2d3f6e0c523311f7e25783280e3eb8f4c3f4f629197ccd5d2ab019364f7377cae2cd478434f6a72a0ff9e8fb3b1598499120abae9a81c7347d2e4f
7
- data.tar.gz: c294e594ed285753a459817c5f0495b43b16febe9b30354e1324b4b6cc08fbf4d84cf817a1ef74b25196bcd964e278131ab6af661f666a8d96d05f1c5ec24db9
6
+ metadata.gz: 19aff29b471f8068fefd895621e3e09e62eba0d3fc8847b633fc4ecccf848452871fc9d549f3ffe142c17893b4461141e317b9ef5faa08b8d99bda36596f5441
7
+ data.tar.gz: 33d1da6842d487a97e485a05cbe39a1a4772425cf7e4fc92748cbbb3974c9ed4e7d82d061034723b4298f76c07e8a9221e2b12297a2ed9f4fc20725ca725bd6b
data/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ ## v 0.0.1 - Initial Release
4
+
5
+ Methods added:
6
+ * is_all_of?
7
+ * is_any_of?
8
+ * is_none_of?
9
+
10
+ ## v 1.0.0 - Refinements to methods
11
+
12
+ Methods changed:
13
+ * is_x_of? to x_of?
14
+
15
+ ## v 2.0.0 - Monkey Patch to Module
16
+
17
+ Updated Izzy to use module instead of explicit patch to object.
18
+
19
+ ### v 2.1.0 - Matcher Methods
20
+
21
+ Added matchers which support === evaluation
22
+
23
+ Methods added:
24
+ * matches_all?
25
+ * matches_any?
26
+ * matches_none?
27
+ * [private] method_check
28
+ * [private] matcher_check
29
+
30
+ ## v 3.0.0 - Multi Matchers
31
+
32
+ Removed implied ? from boolean matchers, prompting version up. Added multi matching capability to matchers, allowing for multiple conditionals to be passed as an array.
33
+
34
+ Methods changed:
35
+ * matches_all?
36
+ * matches_any?
37
+ * matches_none?
38
+ * [private] matcher_check
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Izzy
2
2
 
3
3
  [![Build Status](https://travis-ci.org/baweaver/izzy.png?branch=master)](https://travis-ci.org/baweaver/izzy)
4
+ [![Code Climate](https://codeclimate.com/github/baweaver/izzy.png)](https://codeclimate.com/github/baweaver/izzy)
4
5
  [![Coverage Status](https://coveralls.io/repos/baweaver/izzy/badge.png?branch=master)](https://coveralls.io/r/baweaver/izzy?branch=master)
5
6
 
6
7
  Monkey patch to object to make for a nicer time of conditionals! Just install the gem and you're ready to go!
@@ -52,9 +53,9 @@ brandon = Person.new('brandon', 23, 'm')
52
53
 
53
54
  ...and do some comparisons!
54
55
  ```ruby
55
- brandon.all_of?(:older_than_18, :male, :me, :geek) # => true
56
- brandon.none_of?(:younger_than_18, :female) # => true
57
- brandon.any_of?(:male, :female, :geek) # => true
56
+ brandon.all_of? :older_than_18, :male, :me, :geek # => true
57
+ brandon.none_of? :younger_than_18, :female # => true
58
+ brandon.any_of? :male, :female, :geek # => true
58
59
  ```
59
60
 
60
61
  Maybe boolean comparisons aren't your cup of tea. Izzy has you covered my friend:
@@ -65,6 +66,32 @@ brandon.matches_none? name: /br&/, age: (30..40) # => true
65
66
  ```
66
67
  Izzy compares on === much like a case statement, allowing you to regex and range away! You can even do type checks while you're at it.
67
68
 
69
+ ```ruby
70
+ brandon.matches_all? name: String, age: Integer
71
+ ```
72
+
73
+ Why stop there? Need a bit more power? We have Lambdas for that!
74
+
75
+ ```ruby
76
+ brandon.matches_all? name: -> n { n.length > 3 }, age: -> a { a.odd? } # => true
77
+ ```
78
+
79
+ ....or let's push it further for some interesting results:
80
+
81
+ ```ruby
82
+ brandon.matches_all?(
83
+ name: [
84
+ /br/, /an/, -> n { n.length > 5 }
85
+ ],
86
+ age: [
87
+ (20..30), -> a { a > 20 }
88
+ ]
89
+ )
90
+
91
+ # => true
92
+
93
+ ```
94
+
68
95
  Simple to the point, no more mess of && or || checks for the same object. All you have to do is include Izzy in your object and you're ready to go!
69
96
 
70
97
  ## Installation
data/lib/izzy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Izzy
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0'
3
3
  end
data/lib/izzy.rb CHANGED
@@ -14,24 +14,28 @@ module Izzy
14
14
  end
15
15
 
16
16
  def matches_all?(matchers = {})
17
- matchers.all? &matcher_check
17
+ matchers.all? &matcher_check(:all?)
18
18
  end
19
19
 
20
20
  def matches_any?(matchers = {})
21
- matchers.any? &matcher_check
21
+ matchers.any? &matcher_check(:any?)
22
22
  end
23
23
 
24
24
  def matches_none?(matchers = {})
25
- matchers.none? &matcher_check
25
+ matchers.none? &matcher_check(:any?)
26
26
  end
27
27
 
28
28
  private
29
29
 
30
30
  def method_check
31
- -> method { (m = "#{method}?".to_sym) && self.respond_to?(m) && self.send(m) }
31
+ -> m { self.respond_to?(m) && self.send(m) }
32
32
  end
33
33
 
34
- def matcher_check
35
- -> m { (m, val = *m) && self.respond_to?(m) && val === self.send(m) }
34
+ def matcher_check(type = :all?)
35
+ -> matcher {
36
+ m, val = *matcher
37
+ values = val.is_a?(Array) ? val : Array[val]
38
+ values.send(type) { |v| self.respond_to?(m) && v === self.send(m) }
39
+ }
36
40
  end
37
41
  end
data/spec/izzy_spec.rb CHANGED
@@ -41,31 +41,31 @@ describe 'Person' do
41
41
 
42
42
  describe '#all_of?' do
43
43
  it 'returns true if Person matches all of the conditions' do
44
- expect(@person.all_of? :older_than_18, :male, :geek).to be_true
44
+ expect(@person.all_of? :older_than_18?, :male?, :geek?).to be_true
45
45
  end
46
46
 
47
47
  it 'returns false if Person does not match all of the conditions' do
48
- expect(@person.all_of? :younger_than_18, :male).to be_false
48
+ expect(@person.all_of? :younger_than_18, :male?).to be_false
49
49
  end
50
50
  end
51
51
 
52
52
  describe '#any_of?' do
53
53
  it 'returns true if Person matches any of the conditions' do
54
- expect(@person.any_of? :older_than_18, :female, :geek).to be_true
54
+ expect(@person.any_of? :older_than_18?, :female?, :geek?).to be_true
55
55
  end
56
56
 
57
57
  it 'returns false if Person matches none of the conditions' do
58
- expect(@person.any_of? :younger_than_18, :female).to be_false
58
+ expect(@person.any_of? :younger_than_18, :female?).to be_false
59
59
  end
60
60
  end
61
61
 
62
62
  describe '#none_of?' do
63
63
  it 'returns true if Person matches none of the conditions' do
64
- expect(@person.none_of? :younger_than_18, :female).to be_true
64
+ expect(@person.none_of? :younger_than_18, :female?).to be_true
65
65
  end
66
66
 
67
67
  it 'returns false if Person matches any of the conditions' do
68
- expect(@person.none_of? :older_than_18, :female, :geek).to be_false
68
+ expect(@person.none_of? :older_than_18?, :female?, :geek?).to be_false
69
69
  end
70
70
  end
71
71
 
@@ -76,6 +76,15 @@ describe 'Person' do
76
76
  ).to be_true
77
77
  end
78
78
 
79
+ it 'returns true for multiple conditionals' do
80
+ expect(
81
+ @person.matches_all?(
82
+ name: [/br/, /an/],
83
+ age: [(20..30), -> a { a < 30 }]
84
+ )
85
+ ).to be_true
86
+ end
87
+
79
88
  it 'returns false if Person does not match all conditions' do
80
89
  expect(
81
90
  @person.matches_all?(name: /br/, age: (25..30))
@@ -90,6 +99,16 @@ describe 'Person' do
90
99
  ).to be_true
91
100
  end
92
101
 
102
+ it 'returns true for multiple conditionals' do
103
+ expect(
104
+ @person.matches_any?(
105
+ name: [/br/, /an/],
106
+ age: [(30..40), -> a { a > 30 }]
107
+ )
108
+ ).to be_true
109
+ end
110
+
111
+
93
112
  it 'returns false if Person does not match any conditions' do
94
113
  expect(
95
114
  @person.matches_any?(name: /br$/, age: (25..30))
@@ -98,13 +117,22 @@ describe 'Person' do
98
117
  end
99
118
 
100
119
  describe '#matches_none?' do
101
- it 'returns true if Person matches all of the conditions' do
120
+ it 'returns true if Person matches none of the conditions' do
102
121
  expect(
103
122
  @person.matches_none?(name: /br$/, age: (25..30))
104
123
  ).to be_true
105
124
  end
106
125
 
107
- it 'returns false if Person does not match any conditions' do
126
+ it 'returns true for multiple conditionals' do
127
+ expect(
128
+ @person.matches_none?(
129
+ name: [/br$/, /foo/],
130
+ age: [(30..40), -> a { a > 30 }]
131
+ )
132
+ ).to be_true
133
+ end
134
+
135
+ it 'returns false if Person matches any of the conditions' do
108
136
  expect(
109
137
  @person.matches_none?(name: /br/, age: (25..30))
110
138
  ).to be_false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izzy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,6 +63,7 @@ files:
63
63
  - .gitignore
64
64
  - .rspec
65
65
  - .travis.yml
66
+ - CHANGELOG.md
66
67
  - Gemfile
67
68
  - LICENSE.txt
68
69
  - README.md