act_form 0.2.0 → 0.3.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 +4 -4
- data/CODE_OF_CONDUCT.md +2 -2
- data/README.md +8 -4
- data/lib/act_form/model.rb +10 -2
- data/lib/act_form/runnable.rb +15 -0
- data/lib/act_form/version.rb +1 -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: 6c4d2de3c25f9064a56b848baf11d9fdab30c246
|
4
|
+
data.tar.gz: eefcd0907991528371683715f88b1ef6ce5184b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34ce6c8aff8464fd388f744415293b621c2d1e6925b361f27b580fad371a73c330900abfb83f1aa95cef1b325e081d326bd368ed56262edad4da9d5100bdd6de
|
7
|
+
data.tar.gz: 51c1a884694b3c7a0873dcae073978f9377f52ca46a9e9f08b70363ca08ca739b575a736cc78b6fc5552b0459bdc75de87318c464761757a1b282ad74f5a7e84
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -35,7 +35,7 @@ This code of conduct applies both within project spaces and in public spaces
|
|
35
35
|
when an individual is representing the project or its community.
|
36
36
|
|
37
37
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at
|
38
|
+
reported by contacting a project maintainer at zshuaibin@gmail.com. All
|
39
39
|
complaints will be reviewed and investigated and will result in a response that
|
40
40
|
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
41
|
obligated to maintain confidentiality with regard to the reporter of an
|
@@ -46,4 +46,4 @@ version 1.3.0, available at
|
|
46
46
|
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
47
|
|
48
48
|
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
CHANGED
@@ -31,8 +31,8 @@ form.valid? # => false
|
|
31
31
|
form.errors.full_messages # => ["Name require a value"]
|
32
32
|
```
|
33
33
|
|
34
|
-
#### Difference between
|
35
|
-
`required` run before validation, it will cancel other validations if return false.
|
34
|
+
#### Difference between `required` and `validates_presence_of`
|
35
|
+
`required` will run before the validation, and it will cancel other validations if return false.
|
36
36
|
|
37
37
|
### form object
|
38
38
|
|
@@ -77,7 +77,7 @@ target = Class.new do
|
|
77
77
|
end.new
|
78
78
|
|
79
79
|
form = PhoneForm.new(phone: '12345678901')
|
80
|
-
form.save(target)
|
80
|
+
form.save(target) # same as form.sync(target) and target.save
|
81
81
|
target.phone # => '12345678901'
|
82
82
|
target.saved # => true
|
83
83
|
form.persisted? # => true
|
@@ -99,6 +99,7 @@ target.phone = '12345678901'
|
|
99
99
|
|
100
100
|
form = PhoneForm.new
|
101
101
|
form.init_by(target)
|
102
|
+
form.phone # => '12345678901'
|
102
103
|
form.save # => true
|
103
104
|
target.saved # => true
|
104
105
|
```
|
@@ -152,10 +153,13 @@ class CreateUserCommand < ActForm::Command
|
|
152
153
|
combine UserForm
|
153
154
|
|
154
155
|
def perform
|
155
|
-
|
156
|
+
User.create(attributes)
|
156
157
|
end
|
157
158
|
end
|
158
159
|
|
160
|
+
CreateUserCommand.new
|
161
|
+
# => NoMethodError: private method `new' called for CreateUserCommand:Class
|
162
|
+
|
159
163
|
command = CreateUserCommand.run(phone: '12345678901')
|
160
164
|
if command.success?
|
161
165
|
@user = command.result
|
data/lib/act_form/model.rb
CHANGED
@@ -18,10 +18,18 @@ module ActForm
|
|
18
18
|
super attrs.select { |k, _| respond_to?("#{k}=") }
|
19
19
|
end
|
20
20
|
|
21
|
+
def record=(record)
|
22
|
+
if record.respond_to?(:attributes)
|
23
|
+
@record = record
|
24
|
+
else
|
25
|
+
raise ArgumentError, 'Record must respond to attributes method!'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
21
29
|
# Record must respond_to attributes method
|
22
30
|
def init_by(record, **attrs)
|
23
|
-
|
24
|
-
_attrs = record.attributes.extract! *self.class.attribute_set.keys.map(&:to_s)
|
31
|
+
record = record
|
32
|
+
_attrs = @record.attributes.extract! *self.class.attribute_set.keys.map(&:to_s)
|
25
33
|
assign_attributes _attrs.merge(attrs)
|
26
34
|
end
|
27
35
|
|
data/lib/act_form/runnable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
|
3
3
|
module ActForm
|
4
|
+
class RunError < StandardError; end
|
4
5
|
module Runnable
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
|
@@ -12,6 +13,10 @@ module ActForm
|
|
12
13
|
def run(*args)
|
13
14
|
new(*args).run
|
14
15
|
end
|
16
|
+
|
17
|
+
def run!(*args)
|
18
|
+
new(*args).run!
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def has_errors?
|
@@ -26,6 +31,16 @@ module ActForm
|
|
26
31
|
self
|
27
32
|
end
|
28
33
|
|
34
|
+
def run!
|
35
|
+
if valid?
|
36
|
+
@result = perform
|
37
|
+
@performed = true
|
38
|
+
result
|
39
|
+
else
|
40
|
+
raise RunError, 'Verification failed'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
29
44
|
def perform; end
|
30
45
|
|
31
46
|
def success?
|
data/lib/act_form/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zires
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|