readymade 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +68 -11
- data/lib/readymade/form.rb +10 -12
- data/lib/readymade/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4fa8901d76050e8ef3597f3e079ebbfa6bcd565dbc05a22dc3578616da556b1
|
4
|
+
data.tar.gz: e52a10d9513e21c61501305edae074bd7e80aa00a993f4f3bba8b266d1e420c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5fca515c5b236aa72f49f84326d4e6b02e50d7af50636e8fd79774fb5d246d42a7f82341864729f25051dbf24f9d937c72ef7ae9a76ab794ecca6e0b61eeb3c
|
7
|
+
data.tar.gz: 671f7bdf6ba9362306e790bc6ed02d7c08d3007110d6f256072b4efd5cca0f88719a080489fe023f1e60c3d7ae7de050da252637d2a638fa28665e2f337d7b58
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Readymade 0.1.
|
1
|
+
# Readymade 0.1.8
|
2
2
|
|
3
3
|
This gems contains basic components to follow [ABDI architecture](https://github.com/OrestF/OrestF/blob/master/abdi/ABDI_architecture.md)
|
4
4
|
|
@@ -29,13 +29,35 @@ Inherit your components from:
|
|
29
29
|
|
30
30
|
### Readymade::Response
|
31
31
|
|
32
|
-
```
|
32
|
+
```ruby
|
33
|
+
response = Readymade::Response.new(:success, my_data: data)
|
34
|
+
response.success? # true
|
35
|
+
response =Readymade::Response.new(:fail, errors: errors)
|
36
|
+
response.success? # false
|
37
|
+
response.fail? # true
|
38
|
+
response.status # 'fail'
|
39
|
+
response.data # { errors: { some: 'errors' } }
|
40
|
+
```
|
33
41
|
|
34
42
|
### Readymade::Form
|
35
43
|
|
36
|
-
|
44
|
+
Check more form features examples in `lib/readymade/form.rb`
|
45
|
+
```ruby
|
46
|
+
class Orders::Forms::Create < Readymade::Form
|
47
|
+
PERMITTED_ATTRIBUTES = %i[email name category country customer]
|
48
|
+
REQUIRED_ATTRIBUTES = %i[email]
|
49
|
+
|
50
|
+
validates :customer, presence: true, if: args[:validate_customer]
|
51
|
+
end
|
52
|
+
|
53
|
+
order_form = Orders::Forms::Create.new(params, order: order, validate_customer: false)
|
37
54
|
|
38
|
-
|
55
|
+
order_form.valid? # true
|
56
|
+
|
57
|
+
|
58
|
+
```
|
59
|
+
|
60
|
+
#### form_options
|
39
61
|
|
40
62
|
```ruby
|
41
63
|
# app/forms/my_form.rb
|
@@ -57,17 +79,17 @@ end
|
|
57
79
|
# app/controllers/items_controller.rb
|
58
80
|
|
59
81
|
def new
|
60
|
-
@
|
82
|
+
@form = MyForm.form_options(company: current_company)
|
61
83
|
end
|
62
84
|
```
|
63
85
|
|
64
86
|
```slim
|
65
87
|
/ app/views/items/new.html.slim
|
66
88
|
|
67
|
-
= f.select :category, collection: @
|
68
|
-
= f.select :country, collection: @
|
69
|
-
= f.text_field :email, required: @
|
70
|
-
= f.text_field :name, required: @
|
89
|
+
= f.select :category, collection: @form[:categories]
|
90
|
+
= f.select :country, collection: @form[:countries]
|
91
|
+
= f.text_field :email, required: @form.required?(:email) # true
|
92
|
+
= f.text_field :name, required: @form.required?(:name) # false
|
71
93
|
```
|
72
94
|
|
73
95
|
### Readymade::InstantForm
|
@@ -80,11 +102,46 @@ Readymade::InstantForm.new(my_params, permitted: %i[name phone], required: %i[em
|
|
80
102
|
|
81
103
|
### Readymade::Action
|
82
104
|
|
83
|
-
```
|
105
|
+
```ruby
|
106
|
+
class Orders::Actions::SendNotifications < Readymade::Action
|
107
|
+
def call
|
108
|
+
send_email
|
109
|
+
send_push
|
110
|
+
send_slack
|
111
|
+
|
112
|
+
response(:success, record: record, any_other_data: data)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
response = Orders::Actions::SendNotifications.call(order: order)
|
119
|
+
|
120
|
+
response.fail? # false
|
121
|
+
response.success? # true
|
122
|
+
response.data[:record]
|
123
|
+
response.data[:any_other_data]
|
124
|
+
```
|
84
125
|
|
85
126
|
### Readymade::Operation
|
86
127
|
|
87
|
-
|
128
|
+
Provides set of help methods like: `build_form`, `form_valid?`, `validation_fail`, `save_record`, etc.
|
129
|
+
```ruby
|
130
|
+
class Orders::Operations::Create < Readymade::Operation
|
131
|
+
def call
|
132
|
+
build_record
|
133
|
+
build_form
|
134
|
+
return validation_fail unless form_valid?
|
135
|
+
|
136
|
+
assign_attributes
|
137
|
+
return validation_fail unless record_valid?
|
138
|
+
|
139
|
+
save_record
|
140
|
+
|
141
|
+
success(record: record)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
88
145
|
|
89
146
|
|
90
147
|
## Development
|
data/lib/readymade/form.rb
CHANGED
@@ -147,21 +147,19 @@ module Readymade
|
|
147
147
|
|
148
148
|
# EXAMPLE
|
149
149
|
# class Items::Forms::Create::Value < ::Readymade::Form
|
150
|
-
# PERMITTED_ATTRIBUTES = %i[
|
151
|
-
# REQUIRED_ATTRIBUTES = %i[
|
150
|
+
# PERMITTED_ATTRIBUTES = %i[vat_percent price_type item_category].freeze
|
151
|
+
# REQUIRED_ATTRIBUTES = %i[item_category].freeze
|
152
152
|
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
# }
|
160
|
-
# end
|
153
|
+
# def form_options
|
154
|
+
# {
|
155
|
+
# vat_percent: Item::VAT_OPTIONS,
|
156
|
+
# price_type: Item.price_types.keys,
|
157
|
+
# item_category: args[:company].item_categories
|
158
|
+
# }
|
161
159
|
# end
|
162
160
|
|
163
|
-
# @
|
164
|
-
# f.association :item_category, collection: @
|
161
|
+
# @form = Items::Forms::Create.form_options(company: current_company)
|
162
|
+
# f.association :item_category, collection: @form[:item_category], required: @form.required?(:item_category)
|
165
163
|
|
166
164
|
def self.form_options(**args)
|
167
165
|
Readymade::Form::FormOptions.new(**args.merge!(form_class: self))
|
data/lib/readymade/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readymade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OrestF
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|