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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d8b08e5bcf92035a49dbec37847653f0b99743c2f508c96e50b0aba312b3905
4
- data.tar.gz: 2ec517133167b7ec909d9bf2e77c0fdb185774017f70f8871586ec0eb942925e
3
+ metadata.gz: a4fa8901d76050e8ef3597f3e079ebbfa6bcd565dbc05a22dc3578616da556b1
4
+ data.tar.gz: e52a10d9513e21c61501305edae074bd7e80aa00a993f4f3bba8b266d1e420c1
5
5
  SHA512:
6
- metadata.gz: c2388b93ffa8fd5bb5fe988546dab3383a70ec36296ca0efe6a34475c2e06514a43ff0b12c61986aaf50d6a03c529076c92d1b802647a310a12b44b966dc27d4
7
- data.tar.gz: ec9b42d63e9ba52d2a27fa10ac2ccf572de6c287b14a1f0e9269c7554adb0f10deee2ad0a6fb62a05c5ac7db2854e96abb6ca554774b632bfaa4f037057822b0
6
+ metadata.gz: b5fca515c5b236aa72f49f84326d4e6b02e50d7af50636e8fd79774fb5d246d42a7f82341864729f25051dbf24f9d937c72ef7ae9a76ab794ecca6e0b61eeb3c
7
+ data.tar.gz: 671f7bdf6ba9362306e790bc6ed02d7c08d3007110d6f256072b4efd5cca0f88719a080489fe023f1e60c3d7ae7de050da252637d2a638fa28665e2f337d7b58
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.1.8] - 2022-03-30
5
+
6
+ ### Improvements
7
+
8
+ * Improve README.md and form examples
9
+
4
10
  ## [0.1.6] - 2021-12-20
5
11
 
6
12
  ### Features
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Readymade 0.1.7
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
- ```TODO: add```
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
- ```TODO: add```
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
- #### #form_options
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
- @form_options = MyForm.form_options(company: current_company)
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: @form_options[:categories]
68
- = f.select :country, collection: @form_options[:countries]
69
- = f.text_field :email, required: @form_options.required?(:email) # true
70
- = f.text_field :name, required: @form_options.required?(:name) # false
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
- ```TODO: add```
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
- ```TODO: add```
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
@@ -147,21 +147,19 @@ module Readymade
147
147
 
148
148
  # EXAMPLE
149
149
  # class Items::Forms::Create::Value < ::Readymade::Form
150
- # PERMITTED_ATTRIBUTES = %i[attr1 attr2].freeze
151
- # REQUIRED_ATTRIBUTES = %i[attr1].freeze
150
+ # PERMITTED_ATTRIBUTES = %i[vat_percent price_type item_category].freeze
151
+ # REQUIRED_ATTRIBUTES = %i[item_category].freeze
152
152
  #
153
- # class Value < ::Readymade::Form::Value
154
- # def to_h
155
- # {
156
- # vat_percent: Item::VAT_OPTIONS,
157
- # price_type: Item.price_types.keys,
158
- # item_category: args[:company].item_categories
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
- # @form_options = Items::Forms::Create::Value.new(company: current_company)
164
- # f.association :item_category, collection: @form_options[:item_category]
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))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readymade
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
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.7
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-15 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug