redress 0.3.1 → 0.3.2
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/README.md +22 -0
- data/lib/redress/command.rb +1 -1
- data/lib/redress/form.rb +11 -8
- data/lib/redress/identity.rb +3 -3
- data/lib/redress/types.rb +1 -1
- data/lib/redress/utils/attributes_hash.rb +1 -1
- data/lib/redress/utils/parse_attributes_from_params.rb +3 -2
- data/lib/redress.rb +4 -4
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49bded90385feee506f619deb4d89d6b439a009400473bbd8e4af6278e6d90d5
|
4
|
+
data.tar.gz: 1793066adf0ebe28712b43674918d815d81ebb9eaf254dc59126f92c1acd5527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df64ec1c7fc2089a488dd8a7abc54fdead32af171352eb2316aca075bbdc004010062742542008b0714a2de07c69c4e0061b76026a6b13b3196c55d7a5976214
|
7
|
+
data.tar.gz: 894eb582cc33ee28bf5e35bac36aae0db642910ef9a25611684c878dcf5aae8c311cdb789bf54af402070cef73265ace112355e5b70826437f8c2192fe90b74e
|
data/README.md
CHANGED
@@ -68,6 +68,7 @@ class SimpleForm < ApplicationForm
|
|
68
68
|
attribute :email, String
|
69
69
|
attribute :name_with_email, String
|
70
70
|
attribute :age, Redress::Types::Coercible::Integer
|
71
|
+
atttibute :terms_of_service, Redress::Types::Coercible::Bool
|
71
72
|
end
|
72
73
|
|
73
74
|
validates :name, presence: true
|
@@ -116,6 +117,27 @@ class OrderForm < Redress::Form
|
|
116
117
|
end
|
117
118
|
```
|
118
119
|
|
120
|
+
Form with context:
|
121
|
+
|
122
|
+
```
|
123
|
+
class CommentForm < Redress::Form
|
124
|
+
define_schema do
|
125
|
+
attribute :id, Redress::Types::Coercible::Integer
|
126
|
+
attribute :content, Redress::Types::String
|
127
|
+
end
|
128
|
+
|
129
|
+
validates :content, presence: true
|
130
|
+
validate :unsure_order_state_waiting
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def unsure_order_state_waiting
|
135
|
+
context.order.state?(:waiting)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
CommentForm.new(content: 'Hi').with_context(order: order)
|
140
|
+
```
|
119
141
|
|
120
142
|
### Commands
|
121
143
|
|
data/lib/redress/command.rb
CHANGED
data/lib/redress/form.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'hashie/mash'
|
4
|
+
require 'active_model'
|
5
|
+
require 'dry-struct'
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
7
|
+
require 'redress/utils/parse_attributes_from_params'
|
8
|
+
require 'redress/utils/build_form_from_model'
|
9
|
+
require 'redress/utils/attributes_hash'
|
10
10
|
|
11
11
|
module Redress
|
12
12
|
class Form < Dry::Struct
|
13
13
|
include ActiveModel::Validations
|
14
14
|
include ActiveModel::Conversion
|
15
15
|
|
16
|
-
DEFAULT_NAME =
|
17
|
-
SPLITTER =
|
16
|
+
DEFAULT_NAME = 'Form'
|
17
|
+
SPLITTER = '::'
|
18
18
|
|
19
19
|
attr_reader :context
|
20
20
|
|
@@ -83,9 +83,12 @@ module Redress
|
|
83
83
|
|
84
84
|
def write_attribute(name, value)
|
85
85
|
return unless self.class.attribute?(name)
|
86
|
+
|
86
87
|
@attributes[name] = safe_coercion(name, value)
|
87
88
|
end
|
88
89
|
|
90
|
+
private
|
91
|
+
|
89
92
|
def safe_coercion(name, value)
|
90
93
|
type = self.class.schema[name]
|
91
94
|
type[value]
|
data/lib/redress/identity.rb
CHANGED
@@ -4,15 +4,15 @@ module Redress
|
|
4
4
|
# Gem identity information.
|
5
5
|
module Identity
|
6
6
|
def self.name
|
7
|
-
|
7
|
+
'redress'
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.label
|
11
|
-
|
11
|
+
'Redress'
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.version
|
15
|
-
|
15
|
+
'0.3.2'
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.version_label
|
data/lib/redress/types.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'redress/utils/attributes_hash'
|
4
4
|
|
5
5
|
module Redress
|
6
6
|
module Utils
|
@@ -22,6 +22,7 @@ module Redress
|
|
22
22
|
|
23
23
|
def prefix
|
24
24
|
return if @options[:prefix].blank?
|
25
|
+
|
25
26
|
@prefix ||= @options[:prefix].to_s
|
26
27
|
end
|
27
28
|
|
@@ -29,7 +30,7 @@ module Redress
|
|
29
30
|
@full_prefix ||= "#{prefix}_"
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
+
private
|
33
34
|
|
34
35
|
def extract_attributes
|
35
36
|
hash = model_attributes.merge!(prefix_attibutes)
|
data/lib/redress.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'redress/identity'
|
4
4
|
|
5
5
|
module Redress
|
6
6
|
end
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
8
|
+
require 'redress/types'
|
9
|
+
require 'redress/form'
|
10
|
+
require 'redress/command'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Galeta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -258,8 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
258
|
- !ruby/object:Gem::Version
|
259
259
|
version: '0'
|
260
260
|
requirements: []
|
261
|
-
|
262
|
-
rubygems_version: 2.6.12
|
261
|
+
rubygems_version: 3.0.2
|
263
262
|
signing_key:
|
264
263
|
specification_version: 4
|
265
264
|
summary: Build maintainable Ruby apps
|