result-monad 0.1.1 → 0.1.2

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: 4c05cfa053dac07865ae813bb39039e9b49f7770
4
- data.tar.gz: 3fce9ed465b28e57f3b5b9658d4d9bf8d822978e
3
+ metadata.gz: 06e97a1d838923904e635d8db6d4a2d1aaa408fb
4
+ data.tar.gz: 664c8d07c7c60c78c4a420cd5d1a96a94794bda0
5
5
  SHA512:
6
- metadata.gz: e2c779b1cb7c203d0c0ea6d699db28b167844ab126d27815696171a9422813b22025aa8c355e5a1d952e4c35e636cbe89528cfb307ee0a4ae74f095c07cf756a
7
- data.tar.gz: 64069199a99ca580c78c4623984268d071fcc953c7e0be26833c497682c1fe075ad396c56279d6bdbef33bb9acb6afa00e44a6720b879c2699f5773bbbcf52cb
6
+ metadata.gz: 9fb60c7bd5f36285a4d4ab4f10970698cb82b40bf4e60b09f94d13095a6be1f944ee8a70ad4bdc695cbbe20b01e643976028fa4a7d029e472f22394fa542cf07
7
+ data.tar.gz: 6cf9622293538460ce6760b9d5a1538263e51adcf135c95601a5822f94f19e4ec39a8330eecd68a9831f69a3dab2d944a2f552dc3b5f8c0244a9175c10e66a1a
data/README.md CHANGED
@@ -109,6 +109,9 @@ write it to a local file, and then delete the file on the FTP server. Some thin
109
109
  * Every call to any outside library, even standard library functions are either in a `map` block which
110
110
  gets Captured or they are themselves Captured
111
111
  * No independent action (as in someone calling `copy_file` directly) will execute without its requirements being met.
112
+ * A shortcut to creating an Error value based on some condition, as well as capturing errors generated from testing the
113
+ condition can be seen in `ensure_file`. Any exceptions raised by File.exist?, as well as our condition not being met
114
+ are captured as Error
112
115
 
113
116
  ```ruby
114
117
  require 'net/ftp'
@@ -157,6 +160,23 @@ ftp.transfer_and_delete("5MB.zip")
157
160
  `transfer_and_delete` can return numerous errors but there is no way for this code to raise an exception. Exceptions
158
161
  raised in `map` or `map!` are caught and expressed as `Error`.
159
162
 
163
+ #### Conditionally executing code
164
+
165
+ Using the example above, say we wanted to find and delete the file if we may have accidentally created it.
166
+ This wouldn't be a sensible way of solving this problem, but this illustrates a use case for result base conditionals.
167
+
168
+ ```ruby
169
+ ftp = SensitiveFileFTP.new('speedtest.tele2.net')
170
+ ftp.transfer_and_delete("5MB.zip").or_else do
171
+ ftp.delete_local_file("5MB.zip")
172
+ end
173
+
174
+ # or lets say we wanted to log a success if it worked
175
+
176
+ ftp.transfer_and_delete("5MB.zip").and_then do
177
+ log "Did the thing!"
178
+ end
179
+ ```
160
180
 
161
181
 
162
182
  ## What's next
@@ -186,5 +206,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
186
206
 
187
207
  ## License
188
208
 
189
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
190
-
209
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  class Result
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/result-monad.rb CHANGED
@@ -11,15 +11,15 @@ end
11
11
 
12
12
  def Capture
13
13
  begin
14
- Ok(yield)
14
+ Ok(yield).join!
15
15
  rescue StandardError => e
16
- Error(e)
16
+ Error(e).join!
17
17
  end
18
18
  end
19
19
 
20
20
  class Result
21
- require 'result/error'
22
- require 'result/ok'
21
+ require 'result-monad/error'
22
+ require 'result-monad/ok'
23
23
 
24
24
  def initialize(m)
25
25
  @m = m
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: result-monad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Daniel
@@ -89,7 +89,7 @@ files:
89
89
  - lib/result-monad/error.rb
90
90
  - lib/result-monad/ok.rb
91
91
  - lib/result-monad/version.rb
92
- - result.gemspec
92
+ - result-monad.gemspec
93
93
  homepage: http://gitlab.com/zachdaniel/result-monad
94
94
  licenses:
95
95
  - MIT