either-monad 0.0.1 → 0.0.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: f42a1d3e60ecd54825b268c689ee48be2de686f5
4
- data.tar.gz: 080abd900338fb3b82b37dcd9b03869f96be3cdb
3
+ metadata.gz: b16513779903c1bf9334051f5d13e85e08105176
4
+ data.tar.gz: e62bc45ae20817c744fff565282bef0f513ad4b4
5
5
  SHA512:
6
- metadata.gz: 19963b9a3f84aed941a21e54fc0ec7e428008da8fc6bb45ef948120f1e4180bee50732760478084f3a30fff8b84e176eda608ca6a4437eefb1c9e05e45335c63
7
- data.tar.gz: e59f50faab6fb6cb91a2dc2866062452b0933e43b597bd49ee02667abad01a68724823074d57aaaa05a4994111ed1e9d9b454c41d2627921a02c2e6ef6c723ee
6
+ metadata.gz: f5c3227da2e5a5cb38630a78b4d182a797339fbe062e3e1b5911e3c9fd944c64b75f3479818e45212dc762926917efe91408558a5e8152c36b0b08c3ab9de378
7
+ data.tar.gz: ec285cf53f870c470da4270016d2d2b5024ca86d12148cdafd5d01698ccfb5d9f57dd94516082d36e840df73b78a345e7d8499f33005fe5ef6a6c20209d2a900
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  Either
2
2
  ======
3
3
 
4
+ [![Build Status](https://travis-ci.org/dredozubov/either.svg?branch=master)](https://travis-ci.org/dredozubov/either)
5
+ [![Code Climate](https://codeclimate.com/github/dredozubov/either/badges/gpa.svg)](https://codeclimate.com/github/dredozubov/either)
6
+
4
7
  Dead simple error context framework aka Either monad. Goal of this gem is to
5
8
  provide solid ground to control flow without exceptions and allow simple and
6
- expressive chaining failure context.
9
+ expressive chaining and handling failures gracefully.
10
+
11
+ Don't fear the "monad" part of the name though, you don't have to know what monad is to understand
12
+ how his gem works and use it with ease!
7
13
 
8
14
  Installation
9
15
  ------------
@@ -19,3 +25,73 @@ or in **Gemfile**
19
25
  ``` ruby
20
26
  gem 'either-monad'
21
27
  ```
28
+
29
+
30
+ Examples
31
+ --------
32
+
33
+ All examples taken from production code.
34
+
35
+ ### Chaining computations
36
+
37
+ You can chain computations without fear of losing a failure context. For
38
+ example you can validate a request, make some work and serialize the result
39
+ with:
40
+
41
+ ```ruby
42
+ # results in either Success with serialized result or Failure with context.
43
+ validate(request)
44
+ .bind(->(validated) { search(validated) })
45
+ .bind(->(search_result) { serialize(search_result) })
46
+
47
+ ```
48
+
49
+ If `Failure` has been returned from one of the binded methods, the whole
50
+ expression will be evaluated to this this `Failure` value.
51
+ Each of the binded method(to make sense type-wise) must take unwrapped value
52
+ from previous one, do some work and return new value wrapped in `Success`
53
+ or `Failure`.
54
+
55
+ ### Wrapping values into Success or Failure context
56
+
57
+ ```ruby
58
+ Success[value]
59
+ ```
60
+
61
+ or
62
+
63
+ ```ruby
64
+ Failure[failure_context]
65
+ ```
66
+
67
+ ### Unwrapping values
68
+
69
+ It's just an attribute reader!
70
+
71
+ ```ruby
72
+ result = Success[:foo]
73
+ result.value # => :foo
74
+ ```
75
+
76
+ Ruby version support
77
+ --------------------
78
+
79
+ Gem is supposed to work correctly with the following rubies:
80
+
81
+ * 2.0.0
82
+ * 2.1.4
83
+ * jruby
84
+ * rbx
85
+
86
+ Contributing
87
+ -------------
88
+
89
+ * fork it
90
+ * make some changes and submit a pull request
91
+ * do not make changes to version
92
+
93
+ Contact info
94
+ ------------
95
+
96
+ If you want to contact me or/and some questions - feel free to write me at
97
+ denis.redozubov at gmail or mention me on [twitter](http://twitter.com/rufuse).
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  $LOAD_PATH << File.expand_path('./lib')
2
- require "rotary"
2
+ require "either"
3
3
 
4
4
  task :build do
5
5
  system "gem build either-monad.gemspec"
@@ -1,6 +1,6 @@
1
1
  # Do not instantiate this class EVER
2
2
  class Either
3
- attr_accessor :value
3
+ attr_reader :value
4
4
 
5
5
  def initialize(value)
6
6
  @value = value
@@ -1,4 +1,4 @@
1
- module Either
2
- VERSION = '0.0.1'
1
+ class Either
2
+ VERSION = '0.0.2'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: either-monad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Redozubov