comandor 0.1.1 → 0.1.2
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 +67 -0
- data/lib/comandor/version.rb +1 -1
- data/lib/comandor.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2d6f10465cd542abbbdd70d37605e78796648c
|
4
|
+
data.tar.gz: 7e049e2cdbc0467a560ba10a83d40c348a0632c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae018ea3a46ab885e4742bfa4b8f28074487c0cd47021bc2afa2e02b6bddfe67bc6f9a099b330c212e5c3663b6a9a109aa1121474fae5b204457f7361374770
|
7
|
+
data.tar.gz: 2c69d2e41b7b105550a6cf562599e6698bea2c52872be22b01cf75eeac45ae1581c8c2e6cb73130d8392bb0a76e044a5c0229912a90983300e245728399672a3
|
data/README.md
CHANGED
@@ -42,6 +42,7 @@ class DepositCreate
|
|
42
42
|
# or fail? (failed?) if it’s invalid.
|
43
43
|
# And you can get all errors with #errors method.
|
44
44
|
def perform
|
45
|
+
# .error method adds message to the :amount field
|
45
46
|
return error(:amount, 'Deposit amount should be more than $100') if @amount < 100
|
46
47
|
create_deposit
|
47
48
|
end
|
@@ -93,6 +94,72 @@ end
|
|
93
94
|
in use:
|
94
95
|
```ruby
|
95
96
|
delivery = InvoiceSend.new.perform('renat@aomega.co', 100)
|
97
|
+
if delivery.success?
|
98
|
+
# all good
|
99
|
+
puts delivery.result
|
100
|
+
else
|
101
|
+
# Houston, we have a problem
|
102
|
+
puts deliver.errors.inspect
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
state methods:
|
107
|
+
```ruby
|
108
|
+
# was last .perform call success or not
|
109
|
+
delivery.success?
|
110
|
+
|
111
|
+
# results of .perform call
|
112
|
+
delivery.result
|
113
|
+
|
114
|
+
# Hash of errors
|
115
|
+
#{
|
116
|
+
# 'field1': ['error message 1', 'error message 2'],
|
117
|
+
# 'field2': ['error message 3']
|
118
|
+
#}
|
119
|
+
delivery.errors
|
120
|
+
```
|
121
|
+
|
122
|
+
one more example:
|
123
|
+
```ruby
|
124
|
+
class User::Registration
|
125
|
+
attr_reader :user, :bank_account
|
126
|
+
extend Comandor
|
127
|
+
|
128
|
+
def initialize(params)
|
129
|
+
@params = params
|
130
|
+
end
|
131
|
+
|
132
|
+
def perform
|
133
|
+
create_user! && create_bank_account!
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def create_user!
|
139
|
+
@user = User.new(@params)
|
140
|
+
return true if @user.save
|
141
|
+
error(:user, @user.errors.to_a)
|
142
|
+
false
|
143
|
+
end
|
144
|
+
|
145
|
+
def create_bank_account!
|
146
|
+
@bank_account = Bank::Account.new(user: @user)
|
147
|
+
return true if @bank_account.save
|
148
|
+
error(:bank_account, @bank_account.errors.to_a)
|
149
|
+
false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
example of using:
|
155
|
+
```ruby
|
156
|
+
registration = User::Registration.new(user_params).perform
|
157
|
+
if registration.success?
|
158
|
+
puts registration.user.inspect
|
159
|
+
puts registration.bank_account.inspect
|
160
|
+
else
|
161
|
+
puts registration.errors
|
162
|
+
end
|
96
163
|
```
|
97
164
|
|
98
165
|
## Development
|
data/lib/comandor/version.rb
CHANGED
data/lib/comandor.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comandor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renat Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|