mu-result 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec6059760dd74a847a598f17b84dee0ad3028a2c5c6e7afd5b8bf5a8815c0922
4
- data.tar.gz: fde0c2077ce8690b98bba79c9b8a9654c11f3db221a7220807c8840e9b9a9140
3
+ metadata.gz: 7035a2ec94da66780f5ad89cc4cc1975a16633e2021b7bbc0366007ae5100773
4
+ data.tar.gz: 10c5f2b8f40fdfebe315663551f954b16049ad84a6327fa78e3e29ac44f84fe0
5
5
  SHA512:
6
- metadata.gz: e7976d5f7fa13447ce500aa913327a02440cf3590e2e01543e6c7362d096cf91beeca8693cfc9bad11bd6dc892c35279865d8ebf25fd06b808202b2bdd9f058c
7
- data.tar.gz: eeb98d41c5add154fe3abe0878f0ea0417f842498e1d9904c1582e31e168f81baeec4b6e745466fd9d1e7f9d424268ec08ab5c5f98661982b844bc3c9a8d3ee3
6
+ metadata.gz: 8d4fbb1d0c9d670d2ae6073d293780de9ec232035732720779b205771f43239a0a3394673aa9f4317155ff6ec5eee8dc0f8fb142a8399363213b00da1b7ed4ee
7
+ data.tar.gz: 1ecc708bdd34a381a034613ae6d85def2a846e2542e136b5de1542205fa55538dee83387ca4796400e6819eaf512875ba734079c50c3b70c42d0968888a8373b
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 1.2.0
4
+
5
+ - Adds `BaseResult#unwrap`.
6
+
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| 'https://github.com/#{repo_name}' }
4
-
5
3
  # Specify your gem's dependencies in mu-result.gemspec
6
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mu-result (1.1.0)
4
+ mu-result (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -24,6 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ```ruby
26
26
  include 'mu'
27
+
27
28
  result = Result.success
28
29
  result.success? # => true
29
30
  result = Result.error
@@ -34,6 +35,25 @@ result = Result.success(name: 'Arthur Dent', answer: 42)
34
35
  result.data # => { name: 'Arthur Dent', answer: 42 }
35
36
  ```
36
37
 
38
+ ### Unwrap
39
+
40
+ When you want to access to a specific field of the result, you can _unwrap_ it:
41
+
42
+ ```ruby
43
+ result = Result.success(user: 'olistik', role: :developer)
44
+ result.unwrap(:user) # => 'olistik'
45
+ result.unwrap(:role) # => :developer
46
+ result.unwrap(:name) # => raises `StandardError (The symbol 'name' is not included in the result data object.)`
47
+ ```
48
+
49
+ This is a way to avoid getting unwanted nil values out of the result when passing the wrong field:
50
+
51
+ ```ruby
52
+ result = Result.success(user: 'olistik', role: :developer)
53
+ value = result.data[:users] # => nil, this could lead to an annoying bug later on because we're not aware there's a typo in `:users`, yet.
54
+ value = result.unwrap(:users) # This raises an exception instead, making it evident that we're using the wrong name for the field.
55
+ ```
56
+
37
57
  ## Development
38
58
 
39
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -27,6 +27,16 @@ module Mu
27
27
  def error?
28
28
  !success?
29
29
  end
30
+
31
+ def unwrap(symbol = nil)
32
+ return data if symbol.nil?
33
+
34
+ if !data.respond_to?(:include?) || !data.include?(symbol)
35
+ raise StandardError.new("The symbol '#{symbol}' is not included in the result data object.")
36
+ end
37
+
38
+ return data[symbol]
39
+ end
30
40
  end
31
41
 
32
42
  end
@@ -1,5 +1,5 @@
1
1
  module Mu
2
2
  module Result
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mu-result
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - olistik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2020-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,7 @@ files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
+ - CHANGELOG.md
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
67
68
  - Gemfile.lock