simple_command 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_command.rb +12 -5
- data/lib/simple_command/version.rb +1 -1
- data/spec/simple_command_spec.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3544ff81fdeafe60042fd5a29e4a3c5fb26b6091
|
4
|
+
data.tar.gz: e7d4c7ab4d38ba73ce1ba4967b2ededf94b8b53c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1087bc60e810ba53ea0554f762f78e4d4f2359d167a2788e92d9d6cd64b290b57228fba4b6f4c407bc8e682a4bc654b8652542de3798457a4310dbf921f0a2
|
7
|
+
data.tar.gz: ba370480e93a8578499231f5ac784f59820a6239089865d2a5bcd6b91dd22ea7767229608a86a08024321fff29dde495d2d0d172009869737779fa871b9defeb
|
data/lib/simple_command.rb
CHANGED
@@ -35,14 +35,21 @@ module SimpleCommand
|
|
35
35
|
@errors ||= {}
|
36
36
|
end
|
37
37
|
|
38
|
+
def add_error(key, value)
|
39
|
+
errors[key] ||= []
|
40
|
+
errors[key] << value
|
41
|
+
errors[key].uniq!
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_errors(errors_hash)
|
45
|
+
errors_hash.each do |key, values|
|
46
|
+
values.each { |value| add_error key, value }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
38
50
|
private
|
39
51
|
|
40
52
|
def performed?
|
41
53
|
@performed ||= false
|
42
54
|
end
|
43
|
-
|
44
|
-
def add_error(key, value)
|
45
|
-
errors[key] ||= []
|
46
|
-
errors[key] << value
|
47
|
-
end
|
48
55
|
end
|
data/spec/simple_command_spec.rb
CHANGED
@@ -79,6 +79,39 @@ describe SimpleCommand do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
describe '#add_error' do
|
83
|
+
before do
|
84
|
+
command.add_error :some_error, 'some error description'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'adds the error' do
|
88
|
+
expect(command.errors[:some_error]).to eq(['some error description'])
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'adds the same error only once' do
|
92
|
+
command.add_error :some_error, 'some error description'
|
93
|
+
expect(command.errors[:some_error]).to eq(['some error description'])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#add_errors' do
|
98
|
+
let(:errors) do
|
99
|
+
{
|
100
|
+
some_error: ['some error description'],
|
101
|
+
another_error: ['another error description']
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
before do
|
106
|
+
command.add_errors errors
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'populates #errors with the added errors' do
|
110
|
+
expect(command.errors[:some_error]).to eq(errors[:some_error])
|
111
|
+
expect(command.errors[:another_error]).to eq(errors[:another_error])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
82
115
|
describe '#errors' do
|
83
116
|
let(:errors) { command.perform.errors }
|
84
117
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Pavoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|