viator 0.1.0 → 0.1.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 +4 -4
- data/README.md +20 -11
- data/lib/viator/version.rb +1 -3
- data/lib/viator.rb +8 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a46418413915c7edfcb09ef610490e9acaf187b
|
4
|
+
data.tar.gz: 4f18d9be7fb6c3702baba3a067b67cbe4be631df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d5abfaaedb98580679e0d098c26b9f5295b809eb3cf5d5f220a634bc608db62eac289163d75aacc7a99c47ad88155daaa96490b5a7ad3e25bf4fe860bb5e32
|
7
|
+
data.tar.gz: ad61fc8b000d7b28cb971bb26680fe7de23aee4831c944755d2100c6d74787c93cd146641ad13ca49794177fdcb96adf312b3c2f624d51bf86d2ee069d4bcb37
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Sometimes exceptions are not what I want. Sometimes they are ugly. Sometimes the
|
|
6
6
|
result = User.create('pogs_for_life', 'password', 'pogsandhorses@geocities.com')
|
7
7
|
|
8
8
|
if result.success?
|
9
|
-
do_something
|
9
|
+
do_something(result.value)
|
10
10
|
else
|
11
11
|
result.errors.each { |e| do_something_else(e) }
|
12
12
|
end
|
@@ -30,22 +30,31 @@ or on the console:
|
|
30
30
|
## Usage
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
eh = Viator.new
|
34
|
-
eh.success?
|
35
|
-
eh.failure?
|
36
|
-
eh.count
|
37
|
-
eh.errors
|
33
|
+
eh = Viator.new # create a new error handler
|
34
|
+
eh.success? # true
|
35
|
+
eh.failure? # false
|
36
|
+
eh.count # 0
|
37
|
+
eh.errors # []
|
38
38
|
|
39
39
|
eh.report 'argument invalid!'
|
40
|
-
eh.success?
|
41
|
-
eh.count
|
42
|
-
eh.errors
|
40
|
+
eh.success? # false
|
41
|
+
eh.count # 1
|
42
|
+
eh.errors # ['argument invalid!']
|
43
43
|
|
44
44
|
eh.reset
|
45
|
-
eh.success?
|
45
|
+
eh.success? # true
|
46
46
|
|
47
47
|
eh.value = 'arbitrary data'
|
48
|
-
eh.value
|
48
|
+
eh.value # returns 'nil' if eh.failure?
|
49
|
+
|
50
|
+
# Less Important
|
51
|
+
|
52
|
+
eh = Viator.new(hide_value: false)
|
53
|
+
eh.value = 'berries'
|
54
|
+
eh.report 'There has been an error'
|
55
|
+
eh.value # nil
|
56
|
+
eh.hide_value = true
|
57
|
+
eh.value # 'berries'
|
49
58
|
```
|
50
59
|
|
51
60
|
## Contributing
|
data/lib/viator/version.rb
CHANGED
data/lib/viator.rb
CHANGED
@@ -2,15 +2,17 @@ require 'viator/version'
|
|
2
2
|
|
3
3
|
# Easy and Clean Error Handler
|
4
4
|
class Viator
|
5
|
-
attr_writer
|
6
|
-
attr_reader
|
5
|
+
attr_writer :value
|
6
|
+
attr_reader :errors
|
7
|
+
attr_accessor :hide_value
|
7
8
|
|
8
9
|
class Errors < Array
|
9
10
|
end
|
10
11
|
|
11
|
-
def initialize
|
12
|
-
@errors
|
13
|
-
@value
|
12
|
+
def initialize(options = {})
|
13
|
+
@errors = Errors.new
|
14
|
+
@value = nil
|
15
|
+
@hide_value = (options[:hide_value] != false)
|
14
16
|
end
|
15
17
|
|
16
18
|
def success?
|
@@ -34,6 +36,6 @@ class Viator
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def value
|
37
|
-
@value
|
39
|
+
@value unless failure? && @hide_value
|
38
40
|
end
|
39
41
|
end
|