readymade 0.1.1 → 0.1.5

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: 6238e89120aa1988137e3d64457133724e61843dc214efb5e726703498f24c13
4
- data.tar.gz: 9eafa5715b2835be68c39f5b0880d0c43f9f9c58a0bce4ed14b91dbb132b34b8
3
+ metadata.gz: aefd7011aa28dd0d0e9d5c1d219bc27d2ccbce37d3f28ffc6139a488847c9d8d
4
+ data.tar.gz: 2d5698abc2a38900d633f52315bfd5b05014eb77a6db7958d62146f3cda6be7c
5
5
  SHA512:
6
- metadata.gz: 904961a82ae288d9f086e443b471d14b2f48fb2ed0c854e858129eb127f5c95b805f808090229320740daf859cfff41edd97e5e153ed41e9e889a86d857db968
7
- data.tar.gz: 4f33390f55c6650a366349c6126350049671382171d77d765c8f72c7acae4764501939cd429ba219fb882455560517d10992613393920981ffdea7b17e492599
6
+ metadata.gz: d35e1e55adebd637434ebcae14bdfb99203f6cf4807fa940f019edf87a2c4f14bf36bc7d45dd8af1385740ca06e4445bcaa6ad8b3b18cc4f3e4eef3897d63624
7
+ data.tar.gz: f09669c314759e0b72e9754e0a842f87fcf8a280a94c7994801f9851e739a40b0dc7144c69628bc461b4588a9e13284c29039a3682c7e842d50839c5ca5a2ac6
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [0.1.5] - 2021-12-07
5
+
6
+ ### Improvements
7
+
8
+ * Better errors with Rails 6.1.
9
+
10
+ ## [0.1.4] - 2021-11-22
11
+
12
+ ### Features
13
+
14
+ * Add `Readymade::InstantForm`
15
+
16
+ ### Improvements
17
+
18
+ * Call `build_form` inside `form_valid?` if `@form` is not defined
19
+
20
+ ## [0.1.3] - 2021-11-20
21
+
22
+ ### Improvements
23
+
24
+ * Fix error when required param for instant form is not defined
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readymade (0.1.1)
4
+ readymade (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Lead
1
+ # Readymade
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/readymade`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This gems contains basic components to follow [ABDI architecture](https://github.com/OrestF/OrestF/blob/master/abdi/ABDI_architecture.md)
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,37 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Inherit your components from:
24
+ * `Readymade::Response`
25
+ * `Readymade::Form`
26
+ * `Readymade::InstantForm`
27
+ * `Readymade::Action`
28
+ * `Readymade::Operation`
29
+
30
+ ### Readymade::Response
31
+
32
+ ```TODO: add```
33
+
34
+ ### Readymade::Form
35
+
36
+ ```TODO: add```
37
+
38
+ ### Readymade::InstantForm
39
+
40
+ Permit params and validates presence inline
41
+
42
+ ```ruby
43
+ Readymade::InstantForm.new(my_params, permitted: %i[name phone], required: %i[email]) # permits: name, phone, email; validates on presence: email
44
+ ```
45
+
46
+ ### Readymade::Action
47
+
48
+ ```TODO: add```
49
+
50
+ ### Readymade::Operation
51
+
52
+ ```TODO: add```
53
+
26
54
 
27
55
  ## Development
28
56
 
@@ -20,8 +20,6 @@ module Readymade
20
20
  @args.each do |name, value|
21
21
  instance_variable_set("@#{name}", value)
22
22
  end
23
-
24
- # yield if block_given?
25
23
  end
26
24
 
27
25
  def call; end
@@ -26,7 +26,7 @@ module Readymade
26
26
  @params&.slice!(*permitted_attributes) # if permitted_attributes.present?
27
27
 
28
28
  # dynamically creates attr accessors
29
- @params&.keys&.each do |key|
29
+ @permitted_attributes&.each do |key|
30
30
  singleton_class.class_eval do
31
31
  attr_accessor key
32
32
  end
@@ -84,11 +84,15 @@ module Readymade
84
84
  def sync_errors(from: self, to: record)
85
85
  return if [from, to].any?(&:blank?)
86
86
 
87
- errors = from.errors.instance_variable_get('@messages')
88
- errors.to_h.merge!(to.errors.instance_variable_get('@messages'))
87
+ if Rails.version.to_f > 6.0
88
+ to.errors.merge!(from.errors)
89
+ else
90
+ errors = from.errors.instance_variable_get('@messages').to_h
91
+ errors.merge!(to.errors.instance_variable_get('@messages').to_h)
89
92
 
90
- to.errors.instance_variable_set('@messages', errors)
91
- to.errors.messages.transform_values!(&:uniq) # Does not work with rails 6.1
93
+ to.errors.instance_variable_set('@messages', errors)
94
+ to.errors.messages.transform_values!(&:uniq) # Does not work with rails 6.1
95
+ end
92
96
  rescue FrozenError => _e
93
97
  end
94
98
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Readymade
4
+ class InstantForm < Form
5
+
6
+ end
7
+ end
@@ -14,6 +14,8 @@ module Readymade
14
14
  end
15
15
 
16
16
  def form_valid?
17
+ build_form if @form.nil? && defined?(:build_form)
18
+
17
19
  form.validate
18
20
  end
19
21
 
@@ -24,7 +26,7 @@ module Readymade
24
26
  def record_valid?
25
27
  return true if record.errors.none? && record.valid?
26
28
 
27
- sync_errors_to_form && false
29
+ false
28
30
  end
29
31
 
30
32
  def save_record
@@ -41,6 +43,7 @@ module Readymade
41
43
 
42
44
  def validation_fail(status = :validation_fail, args = {})
43
45
  sync_errors_to_form
46
+
44
47
  response(status, args.merge!(record: record,
45
48
  record_params: record_params,
46
49
  form: form,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readymade
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.5'
5
5
  end
data/lib/readymade.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'readymade/action'
4
4
  require 'readymade/form'
5
+ require 'readymade/instant_form'
5
6
  require 'readymade/operation'
6
7
  require 'readymade/response'
7
8
  require 'readymade/version'
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.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - OrestF
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-03 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -62,6 +62,7 @@ files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
+ - CHANGELOG.md
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
67
68
  - Gemfile.lock
@@ -73,6 +74,7 @@ files:
73
74
  - lib/readymade.rb
74
75
  - lib/readymade/action.rb
75
76
  - lib/readymade/form.rb
77
+ - lib/readymade/instant_form.rb
76
78
  - lib/readymade/operation.rb
77
79
  - lib/readymade/response.rb
78
80
  - lib/readymade/version.rb
@@ -99,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
101
  - !ruby/object:Gem::Version
100
102
  version: '0'
101
103
  requirements: []
102
- rubygems_version: 3.1.6
104
+ rubygems_version: 3.1.4
103
105
  signing_key:
104
106
  specification_version: 4
105
107
  summary: Set of base classes for ABDI architecture