comandor 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: d4469d1f307b4725115cbb4b38b4fceb84370cc5
4
- data.tar.gz: fbb95f8e93f264955fb26866e64e7ff50f8faf1a
3
+ metadata.gz: 9f2d6f10465cd542abbbdd70d37605e78796648c
4
+ data.tar.gz: 7e049e2cdbc0467a560ba10a83d40c348a0632c2
5
5
  SHA512:
6
- metadata.gz: 22c6faa1d2f03189fd07ba13fe00beeb381b01c88431c7e214c435b645117f8e68462e3a7a651289aff8c47c0756100f47a2a815ce41b0127c57ec6099f76148
7
- data.tar.gz: 95e664cb7eb59e9d3d46e15fec9c7ea64bf63470448020f83dfb5fcfbbd20e8f50c16ae50d2583bee738024fd520e568bedf40df16995cacabb863307c803afc
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Comandor
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/comandor.rb CHANGED
@@ -25,7 +25,11 @@ module Comandor
25
25
  # @return [self]
26
26
  def error(key, message)
27
27
  errors[key] ||= []
28
- errors[key] << message
28
+ if message.is_a? Array
29
+ errors[key] = errors[key] + message
30
+ else
31
+ errors[key] << message
32
+ end
29
33
  self
30
34
  end
31
35
 
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.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-06-13 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler