readymade 0.1.7 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d8b08e5bcf92035a49dbec37847653f0b99743c2f508c96e50b0aba312b3905
4
- data.tar.gz: 2ec517133167b7ec909d9bf2e77c0fdb185774017f70f8871586ec0eb942925e
3
+ metadata.gz: 7626ae0687a31a055b912eaa725f049317bc44c38f18ff51b060f71ac188afba
4
+ data.tar.gz: 49de3d0d889bf1ab67e1f424f1c9421b47378e2f5ed10ce6c5cb3e261fcc1e92
5
5
  SHA512:
6
- metadata.gz: c2388b93ffa8fd5bb5fe988546dab3383a70ec36296ca0efe6a34475c2e06514a43ff0b12c61986aaf50d6a03c529076c92d1b802647a310a12b44b966dc27d4
7
- data.tar.gz: ec9b42d63e9ba52d2a27fa10ac2ccf572de6c287b14a1f0e9269c7554adb0f10deee2ad0a6fb62a05c5ac7db2854e96abb6ca554774b632bfaa4f037057822b0
6
+ metadata.gz: 8775ea40ef291da68cbd8e3527bfc5202a29b30a3664b80649070b288d29c92befb6e596ddcc5a81a8b8ef8af32db6f76302576f1a1a405b3fc2121bdbf54fc3
7
+ data.tar.gz: 8cbcf0794b7ad7597f306cc885479afd61ee1eabb030770d2610f776218e2b005a1b3397e65064bdd00181aab1af8abe91c783575c1b29e54c6ba9296d212de4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.2.1] - 2022-04-21
5
+
6
+ ### Improvements
7
+
8
+ * Update collection_response controller helper
9
+
10
+ ## [0.2.0] - 2022-04-13
11
+
12
+ ### Improvements
13
+
14
+ * Add support for ruby 3.0, 3.1
15
+
16
+ ## [0.1.8] - 2022-03-30
17
+
18
+ ### Improvements
19
+
20
+ * Improve README.md and form examples
21
+
4
22
  ## [0.1.6] - 2021-12-20
5
23
 
6
24
  ### Features
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readymade (0.1.7)
4
+ readymade (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,7 +1,13 @@
1
- # Readymade 0.1.7
1
+ # Readymade 0.2.1
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
 
5
+ ### Tested with ruby:
6
+
7
+ - 3.1
8
+ - 3.0
9
+ - 2.7
10
+
5
11
  ## Installation
6
12
 
7
13
  Add this line to your application's Gemfile:
@@ -29,13 +35,35 @@ Inherit your components from:
29
35
 
30
36
  ### Readymade::Response
31
37
 
32
- ```TODO: add```
38
+ ```ruby
39
+ response = Readymade::Response.new(:success, my_data: data)
40
+ response.success? # true
41
+ response = Readymade::Response.new(:fail, errors: errors)
42
+ response.success? # false
43
+ response.fail? # true
44
+ response.status # 'fail'
45
+ response.data # { errors: { some: 'errors' } }
46
+ ```
33
47
 
34
48
  ### Readymade::Form
35
49
 
36
- ```TODO: add```
50
+ Check more form features examples in `lib/readymade/form.rb`
51
+ ```ruby
52
+ class Orders::Forms::Create < Readymade::Form
53
+ PERMITTED_ATTRIBUTES = %i[email name category country customer]
54
+ REQUIRED_ATTRIBUTES = %i[email]
55
+
56
+ validates :customer, presence: true, if: args[:validate_customer]
57
+ end
37
58
 
38
- #### #form_options
59
+ order_form = Orders::Forms::Create.new(params, order: order, validate_customer: false)
60
+
61
+ order_form.valid? # true
62
+
63
+
64
+ ```
65
+
66
+ #### form_options
39
67
 
40
68
  ```ruby
41
69
  # app/forms/my_form.rb
@@ -57,17 +85,17 @@ end
57
85
  # app/controllers/items_controller.rb
58
86
 
59
87
  def new
60
- @form_options = MyForm.form_options(company: current_company)
88
+ @form = MyForm.form_options(company: current_company)
61
89
  end
62
90
  ```
63
91
 
64
92
  ```slim
65
93
  / app/views/items/new.html.slim
66
94
 
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
95
+ = f.select :category, collection: @form[:categories]
96
+ = f.select :country, collection: @form[:countries]
97
+ = f.text_field :email, required: @form.required?(:email) # true
98
+ = f.text_field :name, required: @form.required?(:name) # false
71
99
  ```
72
100
 
73
101
  ### Readymade::InstantForm
@@ -80,11 +108,46 @@ Readymade::InstantForm.new(my_params, permitted: %i[name phone], required: %i[em
80
108
 
81
109
  ### Readymade::Action
82
110
 
83
- ```TODO: add```
111
+ ```ruby
112
+ class Orders::Actions::SendNotifications < Readymade::Action
113
+ def call
114
+ send_email
115
+ send_push
116
+ send_slack
117
+
118
+ response(:success, record: record, any_other_data: data)
119
+ end
120
+ end
121
+ ```
122
+
123
+ ```ruby
124
+ response = Orders::Actions::SendNotifications.call(order: order)
125
+
126
+ response.fail? # false
127
+ response.success? # true
128
+ response.data[:record]
129
+ response.data[:any_other_data]
130
+ ```
84
131
 
85
132
  ### Readymade::Operation
86
133
 
87
- ```TODO: add```
134
+ Provides set of help methods like: `build_form`, `form_valid?`, `validation_fail`, `save_record`, etc.
135
+ ```ruby
136
+ class Orders::Operations::Create < Readymade::Operation
137
+ def call
138
+ build_record
139
+ build_form
140
+ return validation_fail unless form_valid?
141
+
142
+ assign_attributes
143
+ return validation_fail unless record_valid?
144
+
145
+ save_record
146
+
147
+ success(record: record)
148
+ end
149
+ end
150
+ ```
88
151
 
89
152
 
90
153
  ## Development
@@ -12,11 +12,10 @@ module Readymade
12
12
 
13
13
  attr_reader :args, :data
14
14
 
15
- def initialize(**args)
15
+ def initialize(args = {})
16
16
  raise NonKeywordArgumentsError if args.present? && !args.is_a?(Hash)
17
17
 
18
18
  @args = @data = args
19
-
20
19
  @args.each do |name, value|
21
20
  instance_variable_set("@#{name}", value)
22
21
  end
@@ -25,7 +25,7 @@ module Readymade
25
25
 
26
26
  render_json(
27
27
  {
28
- items: serialize_collection(paginate(collection, options), options),
28
+ (options.delete(:root).presence || :items) => serialize_collection(paginate(collection, options), options),
29
29
  count: collection.count
30
30
  },
31
31
  options[:status] || :ok
@@ -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))
@@ -179,7 +177,7 @@ module Readymade
179
177
  end
180
178
 
181
179
  def to_h
182
- raise Readymade::Error.new('define form_options on your form') unless (f = @f_class.new({}, @args)).respond_to?(:form_options)
180
+ raise Readymade::Error.new('define form_options on your form') unless (f = @f_class.new({}, **@args)).respond_to?(:form_options)
183
181
 
184
182
  f.form_options
185
183
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readymade
4
- VERSION = '0.1.7'
4
+ VERSION = '0.2.1'
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.2.1
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-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.1.6
105
+ rubygems_version: 3.3.7
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Set of base classes for ABDI architecture