nasty 0.0.1388164945 → 0.0.1388165564
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nasty.rb +2 -1
- data/lib/nasty/block_specification.rb +35 -0
- data/spec/unit/block_specification_spec.rb +100 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03ada69e453d4784d6c93304dd6396d362c4752e
|
4
|
+
data.tar.gz: 3f5a3775b57439efd2d05738600b8845f265ff6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5648fb4ea8c638d2cd2f5d82f4bb8d55ab3120d2f75e753b87c0b54041489e0ea1874a808afa36900343830b6ca37703b9ade2553cbacee3b50dab8fb394bbe
|
7
|
+
data.tar.gz: 287f5678b2baab3c9fe90e58f37414e46d411fe14e04227f45d8347fd92267538955cea51b1b06d0af7b3ebdc242a508260868699266673613c5697ccbd2c6ea
|
data/lib/nasty.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "nasty/background_job"
|
2
|
+
require "nasty/block_specification"
|
2
3
|
require "nasty/command"
|
3
4
|
require "nasty/composite_command"
|
4
5
|
require "nasty/expose_binding"
|
5
6
|
require "nasty/kernel"
|
7
|
+
require "nasty/lambda_behaviours"
|
6
8
|
require "nasty/log"
|
7
9
|
require "nasty/object"
|
8
|
-
require "nasty/lambda_behaviours"
|
9
10
|
require "nasty/version"
|
10
11
|
|
11
12
|
module Nasty
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Nasty
|
2
|
+
module Specification
|
3
|
+
def or(other_predicate = nil, &block)
|
4
|
+
matcher = create_predicate(other_predicate, &block)
|
5
|
+
create_predicate { |item| self.matches?(item) || matcher.matches?(item) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def and(other_predicate = nil, &block)
|
9
|
+
matcher = create_predicate(other_predicate, &block)
|
10
|
+
create_predicate { |item| self.matches?(item) && matcher.matches?(item) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def not
|
14
|
+
create_predicate { |item| !self.matches?(item) }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def create_predicate(predicate = nil, &block)
|
20
|
+
block_given? ? Nasty::BlockSpecification.new(&block) : predicate
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class BlockSpecification
|
25
|
+
include Nasty::Specification
|
26
|
+
|
27
|
+
def initialize(&block)
|
28
|
+
@block = block
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches?(item)
|
32
|
+
@block.call(item)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Nasty
|
4
|
+
describe BlockSpecification do
|
5
|
+
let(:sut) { BlockSpecification.new { |item| item == true } }
|
6
|
+
|
7
|
+
context "when an item matches" do
|
8
|
+
it "should return true" do
|
9
|
+
sut.matches?(true).should be_true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when an item does not match" do
|
14
|
+
it "should return true" do
|
15
|
+
sut.matches?(false).should be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "or" do
|
20
|
+
context "when one item matches" do
|
21
|
+
it "should return true" do
|
22
|
+
sut.or(BlockSpecification.new {|x| x == false} ).matches?(false).should be_true
|
23
|
+
end
|
24
|
+
it "should return true" do
|
25
|
+
sut.or {|x| x == false} .matches?(false).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when the other item matches" do
|
30
|
+
it "should return true" do
|
31
|
+
sut.or(BlockSpecification.new {|x| x == false} ).matches?(true).should be_true
|
32
|
+
end
|
33
|
+
it "should return true" do
|
34
|
+
sut.or {|x| x == false} .matches?(true).should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when neither item matches" do
|
39
|
+
it "should return false" do
|
40
|
+
sut.or(BlockSpecification.new {|x| x == true}).matches?(false).should be_false
|
41
|
+
end
|
42
|
+
it "should return false" do
|
43
|
+
sut.or {|x| x == true}.matches?(false).should be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "and" do
|
49
|
+
context "when one item matches" do
|
50
|
+
it "should return false" do
|
51
|
+
sut.and(BlockSpecification.new {|x| x == false} ).matches?(false).should be_false
|
52
|
+
end
|
53
|
+
it "should return false" do
|
54
|
+
sut.and {|x| x == false} .matches?(false).should be_false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the other item matches" do
|
59
|
+
it "should return false" do
|
60
|
+
sut.and(BlockSpecification.new {|x| x == false} ).matches?(true).should be_false
|
61
|
+
end
|
62
|
+
it "should return false" do
|
63
|
+
sut.and {|x| x == false} .matches?(true).should be_false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when neither item matches" do
|
68
|
+
it "should return false" do
|
69
|
+
sut.and(BlockSpecification.new {|x| x == true}).matches?(false).should be_false
|
70
|
+
end
|
71
|
+
it "should return false" do
|
72
|
+
sut.and {|x| x == true}.matches?(false).should be_false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when both items match" do
|
77
|
+
it "should return true" do
|
78
|
+
sut.and(BlockSpecification.new {|x| x == true}).matches?(true).should be_true
|
79
|
+
end
|
80
|
+
it "should return true" do
|
81
|
+
sut.and {|x| x == true}.matches?(true).should be_true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "not" do
|
87
|
+
context "when an item matches" do
|
88
|
+
it "should return false" do
|
89
|
+
sut.not.matches?(true).should be_false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when an item does not match" do
|
94
|
+
it "should return true" do
|
95
|
+
sut.not.matches?(false).should be_true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nasty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1388165564
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/nasty.rb
|
83
83
|
- lib/nasty/background_job.rb
|
84
|
+
- lib/nasty/block_specification.rb
|
84
85
|
- lib/nasty/command.rb
|
85
86
|
- lib/nasty/composite_command.rb
|
86
87
|
- lib/nasty/expose_binding.rb
|
@@ -91,6 +92,7 @@ files:
|
|
91
92
|
- lib/nasty/version.rb
|
92
93
|
- nasty.gemspec
|
93
94
|
- spec/spec_helper.rb
|
95
|
+
- spec/unit/block_specification_spec.rb
|
94
96
|
- spec/unit/command_spec.rb
|
95
97
|
- spec/unit/expose_binding_spec.rb
|
96
98
|
- spec/unit/lambda_behaviours_spec.rb
|
@@ -122,6 +124,7 @@ specification_version: 4
|
|
122
124
|
summary: basicly it's a commons library
|
123
125
|
test_files:
|
124
126
|
- spec/spec_helper.rb
|
127
|
+
- spec/unit/block_specification_spec.rb
|
125
128
|
- spec/unit/command_spec.rb
|
126
129
|
- spec/unit/expose_binding_spec.rb
|
127
130
|
- spec/unit/lambda_behaviours_spec.rb
|