act_form 0.1.0 → 0.4.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 +5 -5
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +2 -2
- data/README.md +169 -9
- data/act_form.gemspec +4 -6
- data/lib/act_form.rb +3 -20
- data/lib/act_form/attributes.rb +58 -0
- data/lib/act_form/combinable.rb +24 -27
- data/lib/act_form/locale/en.yml +4 -0
- data/lib/act_form/merge.rb +15 -0
- data/lib/act_form/model.rb +42 -14
- data/lib/act_form/runnable.rb +15 -0
- data/lib/act_form/type.rb +13 -0
- data/lib/act_form/version.rb +1 -1
- metadata +20 -45
- data/lib/act_form/railtie.rb +0 -7
- data/lib/act_form/utils.rb +0 -11
- data/lib/generators/act_form/install_generator.rb +0 -12
- data/lib/generators/templates/forms/record_form.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6dc112ffc52fbda2d69a6f676564bddd36aa6f428fe554c3cbd66e3d05042a47
|
4
|
+
data.tar.gz: 47845d8f3eaafa6595d1b088273f39075387f5ac342bb421040133af62a8aa49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 305fa4843044061a4ee4fb299c767cd16f1cb5d09beb0f70476586e4fb959831e723c9e56908a0712aeb0845baa387849dc979e59ed548b5f90e752cc0c09e5b
|
7
|
+
data.tar.gz: 870fb9bbfe96eb6b33325b9c04192517954708b81b96fbd68724f6bd421073efb7ff33edbb8488a0d900a7275dd404273a6aa9cc6bd20e6fab063c8971245c26
|
data/CHANGELOG.md
ADDED
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
@@ -1,9 +1,174 @@
|
|
1
1
|
# ActForm
|
2
2
|
|
3
|
-
|
3
|
+
ActForm is the gem that provide a simple way to create `form object` or `command object` or `service object`, it only depends on `activemodel >= 5` and provides few api.
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
#### API - `attribute`
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class UserForm < ActForm::Base
|
11
|
+
attribute :name, required: true
|
12
|
+
attribute :age, type: :integer
|
13
|
+
attribute :address
|
14
|
+
attribute :nickname, default: 'nick'
|
15
|
+
attribute :desc, default: ->{ 'desc' }
|
16
|
+
end
|
17
|
+
|
18
|
+
form = UserForm.new(name: 'su', age: '18', address: 'somewhere')
|
19
|
+
form.name # => 'su'
|
20
|
+
form.age # => 18
|
21
|
+
form.address # => 'somewhere'
|
22
|
+
form.nickname # => 'nick'
|
23
|
+
form.desc # => 'desc'
|
24
|
+
# override default
|
25
|
+
form.nickname = 'hello'
|
26
|
+
form.nickname # => 'hello'
|
27
|
+
|
28
|
+
# required
|
29
|
+
form = UserForm.new(age: '18', address: 'somewhere')
|
30
|
+
form.valid? # => false
|
31
|
+
form.errors.full_messages # => ["Name require a value"]
|
32
|
+
```
|
33
|
+
|
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
|
+
|
37
|
+
### form object
|
38
|
+
|
39
|
+
#### API - `valid?`
|
40
|
+
Compliant with the active model api
|
41
|
+
```ruby
|
42
|
+
class PhoneForm < ActForm::Base
|
43
|
+
attribute :phone
|
44
|
+
|
45
|
+
validates_format_of :phone, with: /\A\d{11}\z/i
|
46
|
+
end
|
47
|
+
|
48
|
+
form = PhoneForm.new
|
49
|
+
form.valid? # => false
|
50
|
+
form.errors.full_messages # => ["Phone is invalid"]
|
51
|
+
|
52
|
+
PhoneForm.new(phone: '12345678901').valid? # => true
|
53
|
+
```
|
54
|
+
|
55
|
+
#### API - `sync`
|
56
|
+
sync only copy attributes to target, will not trigger validate
|
57
|
+
```ruby
|
58
|
+
target = Class.new do
|
59
|
+
attr_accessor :phone
|
60
|
+
end.new
|
61
|
+
|
62
|
+
form = PhoneForm.new(phone: '12345678901')
|
63
|
+
form.sync(target)
|
64
|
+
target.phone # => '12345678901'
|
65
|
+
```
|
66
|
+
|
67
|
+
#### API - `save`
|
68
|
+
sync to the target and call the save method when passed the validation
|
69
|
+
```ruby
|
70
|
+
target = Class.new do
|
71
|
+
attr_accessor :phone
|
72
|
+
attr_reader :saved
|
73
|
+
|
74
|
+
def save
|
75
|
+
@saved = true
|
76
|
+
end
|
77
|
+
end.new
|
78
|
+
|
79
|
+
form = PhoneForm.new(phone: '12345678901')
|
80
|
+
form.save(target) # same as form.sync(target) and target.save
|
81
|
+
target.phone # => '12345678901'
|
82
|
+
target.saved # => true
|
83
|
+
form.persisted? # => true
|
84
|
+
```
|
85
|
+
|
86
|
+
#### API - `init_by`
|
87
|
+
`init_by` will copy attributes form target to the form, and set default target.
|
88
|
+
```ruby
|
89
|
+
target = Class.new do
|
90
|
+
attr_accessor :phone
|
91
|
+
attr_reader :saved
|
92
|
+
|
93
|
+
def save
|
94
|
+
@saved = true
|
95
|
+
end
|
96
|
+
end.new
|
97
|
+
|
98
|
+
target.phone = '12345678901'
|
99
|
+
|
100
|
+
form = PhoneForm.new
|
101
|
+
form.init_by(target)
|
102
|
+
form.phone # => '12345678901'
|
103
|
+
form.save # => true
|
104
|
+
target.saved # => true
|
105
|
+
```
|
106
|
+
|
107
|
+
#### API - `combine`
|
108
|
+
form can combine to other forms
|
109
|
+
```ruby
|
110
|
+
class PhoneForm < ActForm::Base
|
111
|
+
attribute :phone
|
112
|
+
validates_format_of :phone, with: /\A\d{11}\z/i
|
113
|
+
end
|
114
|
+
|
115
|
+
class EmailForm < ActForm::Base
|
116
|
+
attribute :email
|
117
|
+
|
118
|
+
validate :check_email
|
119
|
+
|
120
|
+
def check_email
|
121
|
+
errors.add(:email, :blank) if email.blank?
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class UserForm < ActForm::Base
|
126
|
+
combine PhoneForm, EmailForm
|
127
|
+
end
|
128
|
+
|
129
|
+
class AdminForm < ActForm::Base
|
130
|
+
combine PhoneForm
|
131
|
+
end
|
132
|
+
|
133
|
+
user_form = UserForm.new
|
134
|
+
user_form.valid?
|
135
|
+
user_form.errors.full_messages # => ["Phone is invalid", "Email can't be blank"]
|
136
|
+
UserForm.new(phone: '12345678901', email: '1').valid? # => true
|
137
|
+
admin_form = AdminForm.new
|
138
|
+
admin_form.valid?
|
139
|
+
admin_form.errors.full_messages # => ["Phone is invalid"]
|
140
|
+
AdminForm.new(phone: '12345678901').valid? # => true
|
141
|
+
```
|
142
|
+
|
143
|
+
### command/service object
|
6
144
|
|
145
|
+
Command object almost like form object. Command object can't init by `new`, and it has some new features.
|
146
|
+
|
147
|
+
#### API - `perform`, `run`, `success?`, `failure?`
|
148
|
+
|
149
|
+
command object must respond to `perform` method.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
class CreateUserCommand < ActForm::Command
|
153
|
+
combine UserForm
|
154
|
+
|
155
|
+
def perform
|
156
|
+
User.create(attributes)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
CreateUserCommand.new
|
161
|
+
# => NoMethodError: private method `new' called for CreateUserCommand:Class
|
162
|
+
|
163
|
+
command = CreateUserCommand.run(phone: '12345678901')
|
164
|
+
if command.success?
|
165
|
+
@user = command.result
|
166
|
+
# do something...
|
167
|
+
else
|
168
|
+
command.errors.full_messages # => ["Email can't be blank"]
|
169
|
+
# do something...
|
170
|
+
end
|
171
|
+
```
|
7
172
|
## Installation
|
8
173
|
|
9
174
|
Add this line to your application's Gemfile:
|
@@ -18,21 +183,16 @@ And then execute:
|
|
18
183
|
|
19
184
|
Or install it yourself as:
|
20
185
|
|
21
|
-
$ gem install
|
22
|
-
|
23
|
-
## Usage
|
186
|
+
$ gem install act_form
|
24
187
|
|
25
|
-
TODO: Write usage instructions here
|
26
188
|
|
27
189
|
## Development
|
28
190
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
191
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
192
|
|
33
193
|
## Contributing
|
34
194
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/
|
195
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/act_form. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
196
|
|
37
197
|
|
38
198
|
## License
|
data/act_form.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{A simple way to create form/command/service objects.}
|
13
13
|
spec.description = %q{The simple way to create form objects or command/service objects with ActiveModel.}
|
14
|
-
spec.homepage = 'https://github.com/simple-and-powerful/form
|
14
|
+
spec.homepage = 'https://github.com/simple-and-powerful/act-form'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -23,13 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
# end
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = 'exe'
|
27
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
27
|
spec.require_paths = ['lib']
|
29
28
|
|
30
|
-
spec.add_runtime_dependency '
|
31
|
-
spec.add_runtime_dependency 'activemodel', '~> 4.0', '>= 4.0.0'
|
29
|
+
spec.add_runtime_dependency 'activemodel', '>= 5.0.0'
|
32
30
|
|
33
|
-
spec.add_development_dependency 'bundler', '~> 1
|
34
|
-
spec.add_development_dependency 'rake', '~>
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
32
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
35
33
|
end
|
data/lib/act_form.rb
CHANGED
@@ -7,28 +7,11 @@ module ActForm
|
|
7
7
|
include Model
|
8
8
|
end
|
9
9
|
|
10
|
-
class
|
11
|
-
|
12
|
-
def initialize(record, **attrs)
|
13
|
-
@record = record
|
14
|
-
@extract_attrs = @record.attributes.extract! *self.class.attribute_set.map(&:name).map(&:to_s)
|
15
|
-
super(@extract_attrs.merge(attrs))
|
16
|
-
end
|
17
|
-
|
18
|
-
def save
|
19
|
-
if valid?
|
20
|
-
sync(@record)
|
21
|
-
@persisted = @record.save
|
22
|
-
else
|
23
|
-
false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Command < Base
|
10
|
+
class Command
|
11
|
+
include Model
|
29
12
|
include Runnable
|
30
13
|
private_class_method :new
|
31
14
|
end
|
32
15
|
end
|
33
16
|
|
34
|
-
|
17
|
+
I18n.load_path << "#{File.dirname(__FILE__)}/act_form/locale/en.yml"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'act_form/type'
|
2
|
+
|
3
|
+
module ActForm
|
4
|
+
module Attributes
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class_attribute :attribute_set, instance_accessor: false
|
9
|
+
self.attribute_set = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def attributes
|
13
|
+
@attributes || {}
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def get_default(default, default_provided)
|
19
|
+
return if default == default_provided
|
20
|
+
default.respond_to?(:call) ? default.call : default
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
# attribute :name, type: :string
|
25
|
+
# or
|
26
|
+
# attribute :name, :string, required: true
|
27
|
+
def attribute(name, cast_type = :object, **options)
|
28
|
+
name = name.to_s
|
29
|
+
cast_type = options[:type] || cast_type
|
30
|
+
self.attribute_set = attribute_set.merge(name => [cast_type, options])
|
31
|
+
|
32
|
+
define_reader_method name, **options.slice(:default)
|
33
|
+
define_writer_method name, cast_type
|
34
|
+
|
35
|
+
name
|
36
|
+
end
|
37
|
+
alias_method :attr, :attribute
|
38
|
+
|
39
|
+
def define_reader_method(name, default: NO_DEFAULT_PROVIDED)
|
40
|
+
define_method(name) { attributes[name] || get_default(default, NO_DEFAULT_PROVIDED) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def define_writer_method(name, cast_type)
|
44
|
+
define_method("#{name}=") do |value|
|
45
|
+
_value = ActiveModel::Type.lookup(cast_type).deserialize(value)
|
46
|
+
@attributes = attributes.merge({name => _value})
|
47
|
+
_value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
NO_DEFAULT_PROVIDED = Object.new
|
54
|
+
private_constant :NO_DEFAULT_PROVIDED
|
55
|
+
|
56
|
+
end # class_methods
|
57
|
+
end
|
58
|
+
end
|
data/lib/act_form/combinable.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'active_support/concern'
|
2
|
-
require 'act_form/utils'
|
3
2
|
|
4
3
|
module ActForm
|
5
4
|
module Combinable
|
@@ -10,40 +9,38 @@ module ActForm
|
|
10
9
|
self._forms = []
|
11
10
|
end
|
12
11
|
|
12
|
+
def valid?(context = nil)
|
13
|
+
super
|
14
|
+
combined_forms_valid?(context)
|
15
|
+
errors.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def combined_forms_valid?(context)
|
19
|
+
return if _forms.empty?
|
20
|
+
_forms.each do |form_class|
|
21
|
+
form = form_class.new(attributes)
|
22
|
+
form.valid?(context)
|
23
|
+
form.errors.details.each do |attr_name, arr|
|
24
|
+
arr.each do |error|
|
25
|
+
next if error[:error] == :required
|
26
|
+
errors.add(attr_name, error[:error])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
13
32
|
class_methods do
|
14
33
|
|
15
34
|
def combine(*forms)
|
16
35
|
forms.each do |form_class|
|
17
|
-
raise ArgumentError, '
|
36
|
+
raise ArgumentError, "can't combine itself" if form_class == self
|
18
37
|
|
19
38
|
next if self._forms.include?(form_class)
|
20
39
|
|
40
|
+
self.merge_attribute_set_from(form_class)
|
21
41
|
self._forms << form_class
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Utils.merge(self._validators, form_class._validators)
|
26
|
-
|
27
|
-
method_name = form_class.model_name.singular
|
28
|
-
define_method(method_name) { form_class.new(attributes) }
|
29
|
-
form_class._validate_callbacks.each do |callback|
|
30
|
-
filter = callback.filter
|
31
|
-
if filter.is_a?(Symbol) || filter.is_a?(String)
|
32
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
33
|
-
def #{filter}
|
34
|
-
form = #{method_name}
|
35
|
-
form.send(:#{filter})
|
36
|
-
form.errors.messages.each do |attr, _errors|
|
37
|
-
_errors.each { |err| errors.add(attr, err) }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
private :#{filter}
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
end
|
44
|
-
self._validate_callbacks.append *form_class._validate_callbacks
|
45
|
-
end # forms.each
|
46
|
-
end # combine
|
42
|
+
end
|
43
|
+
end
|
47
44
|
|
48
45
|
end
|
49
46
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActForm
|
2
|
+
module Merge
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def merge_attribute_set_from(other)
|
7
|
+
other.attribute_set.each do |attr_name, arr|
|
8
|
+
cast_type, options = arr
|
9
|
+
attribute attr_name, cast_type, options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/act_form/model.rb
CHANGED
@@ -1,27 +1,44 @@
|
|
1
|
-
require 'active_support/core_ext/object/deep_dup'
|
2
1
|
require 'active_model'
|
3
|
-
require '
|
2
|
+
require 'act_form/attributes'
|
3
|
+
require 'act_form/merge'
|
4
4
|
require 'act_form/combinable'
|
5
5
|
|
6
6
|
module ActForm
|
7
7
|
module Model
|
8
8
|
extend ActiveSupport::Concern
|
9
|
-
include ActiveModel::
|
10
|
-
include
|
9
|
+
include ActiveModel::Model
|
10
|
+
include Attributes
|
11
|
+
include Merge
|
11
12
|
|
12
13
|
included do
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
set_callback :validate, :before, :validate_required_attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(attrs={})
|
18
|
+
super attrs.select { |k, _| respond_to?("#{k}=") }
|
19
|
+
end
|
20
|
+
|
21
|
+
def record=(record)
|
22
|
+
raise ArgumentError, 'Record must respond to attributes method!' unless record.respond_to?(:attributes)
|
23
|
+
@record = record
|
24
|
+
end
|
25
|
+
|
26
|
+
# Record must respond_to attributes method
|
27
|
+
def init_by(record, **attrs)
|
28
|
+
self.record = record
|
29
|
+
_attrs = record.attributes.extract! *self.class.attribute_set.keys.map(&:to_s)
|
30
|
+
assign_attributes _attrs.merge(attrs)
|
16
31
|
end
|
17
32
|
|
18
33
|
def sync(target)
|
19
|
-
self.class.attribute_set.
|
20
|
-
|
34
|
+
self.class.attribute_set.keys.each do |attr|
|
35
|
+
next unless target.respond_to?(attr)
|
36
|
+
target.public_send "#{attr}=", public_send(attr)
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
24
|
-
def save(target)
|
40
|
+
def save(target = nil)
|
41
|
+
target ||= @record
|
25
42
|
if valid?
|
26
43
|
sync(target)
|
27
44
|
@persisted = target.save
|
@@ -34,14 +51,25 @@ module ActForm
|
|
34
51
|
!!@persisted
|
35
52
|
end
|
36
53
|
|
54
|
+
private
|
55
|
+
|
56
|
+
def validate_required_attributes
|
57
|
+
self.class.attribute_set.each do |attr_name, arr|
|
58
|
+
_, options = arr
|
59
|
+
next if options.key?(:default)
|
60
|
+
next if !options[:required]
|
61
|
+
if attributes[attr_name].nil?
|
62
|
+
errors.add(attr_name, :required)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
throw(:abort) unless errors.empty?
|
66
|
+
end
|
67
|
+
|
37
68
|
class_methods do
|
38
|
-
private
|
39
69
|
def inherited(child_class)
|
40
|
-
child_class._validators = self._validators.deep_dup
|
41
|
-
child_class._validate_callbacks = self._validate_callbacks.deep_dup
|
42
70
|
child_class.include Combinable
|
43
71
|
super
|
44
72
|
end
|
45
|
-
end
|
73
|
+
end # class_methods
|
46
74
|
end
|
47
75
|
end
|
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,83 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zires
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: virtus
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 1.0.0
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.0'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.0.0
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: activemodel
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
36
16
|
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '4.0'
|
40
17
|
- - ">="
|
41
18
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
19
|
+
version: 5.0.0
|
43
20
|
type: :runtime
|
44
21
|
prerelease: false
|
45
22
|
version_requirements: !ruby/object:Gem::Requirement
|
46
23
|
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '4.0'
|
50
24
|
- - ">="
|
51
25
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
26
|
+
version: 5.0.0
|
53
27
|
- !ruby/object:Gem::Dependency
|
54
28
|
name: bundler
|
55
29
|
requirement: !ruby/object:Gem::Requirement
|
56
30
|
requirements:
|
57
31
|
- - "~>"
|
58
32
|
- !ruby/object:Gem::Version
|
59
|
-
version: '1
|
33
|
+
version: '2.1'
|
60
34
|
type: :development
|
61
35
|
prerelease: false
|
62
36
|
version_requirements: !ruby/object:Gem::Requirement
|
63
37
|
requirements:
|
64
38
|
- - "~>"
|
65
39
|
- !ruby/object:Gem::Version
|
66
|
-
version: '1
|
40
|
+
version: '2.1'
|
67
41
|
- !ruby/object:Gem::Dependency
|
68
42
|
name: rake
|
69
43
|
requirement: !ruby/object:Gem::Requirement
|
70
44
|
requirements:
|
71
45
|
- - "~>"
|
72
46
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
47
|
+
version: '13.0'
|
74
48
|
type: :development
|
75
49
|
prerelease: false
|
76
50
|
version_requirements: !ruby/object:Gem::Requirement
|
77
51
|
requirements:
|
78
52
|
- - "~>"
|
79
53
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
54
|
+
version: '13.0'
|
81
55
|
description: The simple way to create form objects or command/service objects with
|
82
56
|
ActiveModel.
|
83
57
|
email:
|
@@ -87,6 +61,7 @@ extensions: []
|
|
87
61
|
extra_rdoc_files: []
|
88
62
|
files:
|
89
63
|
- ".gitignore"
|
64
|
+
- CHANGELOG.md
|
90
65
|
- CODE_OF_CONDUCT.md
|
91
66
|
- Gemfile
|
92
67
|
- LICENSE.txt
|
@@ -94,19 +69,19 @@ files:
|
|
94
69
|
- Rakefile
|
95
70
|
- act_form.gemspec
|
96
71
|
- lib/act_form.rb
|
72
|
+
- lib/act_form/attributes.rb
|
97
73
|
- lib/act_form/combinable.rb
|
74
|
+
- lib/act_form/locale/en.yml
|
75
|
+
- lib/act_form/merge.rb
|
98
76
|
- lib/act_form/model.rb
|
99
|
-
- lib/act_form/railtie.rb
|
100
77
|
- lib/act_form/runnable.rb
|
101
|
-
- lib/act_form/
|
78
|
+
- lib/act_form/type.rb
|
102
79
|
- lib/act_form/version.rb
|
103
|
-
|
104
|
-
- lib/generators/templates/forms/record_form.rb
|
105
|
-
homepage: https://github.com/simple-and-powerful/form-model
|
80
|
+
homepage: https://github.com/simple-and-powerful/act-form
|
106
81
|
licenses:
|
107
82
|
- MIT
|
108
83
|
metadata: {}
|
109
|
-
post_install_message:
|
84
|
+
post_install_message:
|
110
85
|
rdoc_options: []
|
111
86
|
require_paths:
|
112
87
|
- lib
|
@@ -121,9 +96,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
96
|
- !ruby/object:Gem::Version
|
122
97
|
version: '0'
|
123
98
|
requirements: []
|
124
|
-
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
126
|
-
signing_key:
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.7.7
|
101
|
+
signing_key:
|
127
102
|
specification_version: 4
|
128
103
|
summary: A simple way to create form/command/service objects.
|
129
104
|
test_files: []
|
data/lib/act_form/railtie.rb
DELETED
data/lib/act_form/utils.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module ActForm
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < ::Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../../templates', __FILE__)
|
5
|
-
|
6
|
-
desc 'Create the forms dir and copy record_form.rb'
|
7
|
-
def copy_initializer
|
8
|
-
directory 'forms', 'app/forms'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|