viator 0.1.0 → 0.1.1

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: 9a5704e12bfcdb6349252b3573b42bd5d7063a7a
4
- data.tar.gz: 73b5b89174b62f08f76e4122616ba378897a08b6
3
+ metadata.gz: 9a46418413915c7edfcb09ef610490e9acaf187b
4
+ data.tar.gz: 4f18d9be7fb6c3702baba3a067b67cbe4be631df
5
5
  SHA512:
6
- metadata.gz: afb5e53c070af11e0aeb7e1a24652a36aae2bbe2c15c785d67fbcaceef1b736b42299159ca6988ace28337fa42019d1d44d2beede35d5462c26a56aaa0664081
7
- data.tar.gz: b96835c780d9fc40e15aad6df11be287f9a1357f2e79df0cfdd583a6aba1c1f5798984562db67d4eba6aec4ebc520f61e0538b31f4027a666f3a1677288d8ade
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 result.value
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 # create a new error handler
34
- eh.success? # true
35
- eh.failure? # false
36
- eh.count # 0
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? # false
41
- eh.count # 1
42
- eh.errors # ['argument invalid!']
40
+ eh.success? # false
41
+ eh.count # 1
42
+ eh.errors # ['argument invalid!']
43
43
 
44
44
  eh.reset
45
- eh.success? # true
45
+ eh.success? # true
46
46
 
47
47
  eh.value = 'arbitrary data'
48
- eh.value # returns 'nil' if eh.failure?
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
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class Viator
4
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
5
3
  end
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 :value
6
- attr_reader :errors
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 = Errors.new
13
- @value = nil
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 if success?
39
+ @value unless failure? && @hide_value
38
40
  end
39
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Church