formulario 0.1.6 → 0.1.12
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 +4 -4
- data/Gemfile.lock +17 -17
- data/lib/formulario/fields.rb +1 -0
- data/lib/formulario/fields/collection.rb +18 -18
- data/lib/formulario/fields/exceptional_value.rb +4 -2
- data/lib/formulario/fields/field.rb +8 -0
- data/lib/formulario/fields/float.rb +14 -0
- data/lib/formulario/fields/unvalidated_field.rb +1 -1
- data/lib/formulario/form.rb +23 -15
- data/lib/formulario/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63bcd983db7081db6f273df3552b2a3c303a3ad523645ce708845261a9083eb2
|
4
|
+
data.tar.gz: c61c2edec3d80f0a63b379fff002a0466ff1fe1905c283375970da3c6b0fe338
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09e7e4a46761f274b6f7666367e727a32af5dabe85c4d4ab7da4449b33c5bdfe226cb09aaa71c0750a30c227d3dec0afc00fce99be4270b7751df58ea0da4a0f'
|
7
|
+
data.tar.gz: f7ba1d511605f3fd4bb3cc993148729dab7d9d5dba54de53a853a016fe40b2ef2527c576ccf38fd28f3f624ce0f89c2340a22b037d2f104260fb1fa7a5f7e6b8
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
formulario (0.1.
|
4
|
+
formulario (0.1.12)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
awesome_print (1.8.0)
|
10
|
-
byebug (11.
|
11
|
-
coderay (1.1.
|
12
|
-
diff-lcs (1.
|
13
|
-
docile (1.3.
|
14
|
-
json (2.
|
15
|
-
method_source (0.
|
16
|
-
pry (0.
|
17
|
-
coderay (~> 1.1
|
18
|
-
method_source (~>
|
10
|
+
byebug (11.1.3)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
docile (1.3.5)
|
14
|
+
json (2.5.1)
|
15
|
+
method_source (1.0.0)
|
16
|
+
pry (0.14.0)
|
17
|
+
coderay (~> 1.1)
|
18
|
+
method_source (~> 1.0)
|
19
19
|
pry-byebug (3.7.0)
|
20
20
|
byebug (~> 11.0)
|
21
21
|
pry (~> 0.10)
|
22
|
-
rake (13.0.
|
22
|
+
rake (13.0.3)
|
23
23
|
rspec (3.9.0)
|
24
24
|
rspec-core (~> 3.9.0)
|
25
25
|
rspec-expectations (~> 3.9.0)
|
26
26
|
rspec-mocks (~> 3.9.0)
|
27
|
-
rspec-core (3.9.
|
28
|
-
rspec-support (~> 3.9.
|
29
|
-
rspec-expectations (3.9.
|
27
|
+
rspec-core (3.9.3)
|
28
|
+
rspec-support (~> 3.9.3)
|
29
|
+
rspec-expectations (3.9.4)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
31
|
rspec-support (~> 3.9.0)
|
32
|
-
rspec-mocks (3.9.
|
32
|
+
rspec-mocks (3.9.1)
|
33
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
34
|
rspec-support (~> 3.9.0)
|
35
|
-
rspec-support (3.9.
|
35
|
+
rspec-support (3.9.4)
|
36
36
|
simplecov (0.17.1)
|
37
37
|
docile (~> 1.1)
|
38
38
|
json (>= 1.8, < 3)
|
@@ -52,4 +52,4 @@ DEPENDENCIES
|
|
52
52
|
simplecov (~> 0.17.1)
|
53
53
|
|
54
54
|
BUNDLED WITH
|
55
|
-
2.
|
55
|
+
2.2.3
|
data/lib/formulario/fields.rb
CHANGED
@@ -7,6 +7,7 @@ require "formulario/fields/blank"
|
|
7
7
|
require "formulario/fields/exceptional_value"
|
8
8
|
require "formulario/fields/string"
|
9
9
|
require "formulario/fields/integer"
|
10
|
+
require "formulario/fields/float"
|
10
11
|
require "formulario/fields/boolean"
|
11
12
|
|
12
13
|
require "formulario/fields/default_time_field"
|
@@ -3,21 +3,16 @@ module Formulario
|
|
3
3
|
class Collection < Field
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
def fields
|
7
|
-
raw_value
|
8
|
-
end
|
9
|
-
|
10
|
-
def values
|
11
|
-
fields.map(&:value)
|
12
|
-
end
|
13
|
-
alias :value :values
|
14
|
-
|
15
6
|
def self.[](type)
|
16
7
|
Class.new(self).tap { |typed_class|
|
17
|
-
typed_class.
|
8
|
+
typed_class.fields_type = type
|
18
9
|
}
|
19
10
|
end
|
20
11
|
|
12
|
+
def fields
|
13
|
+
raw_value
|
14
|
+
end
|
15
|
+
|
21
16
|
def exceptional?
|
22
17
|
fields.any?(&:exceptional?)
|
23
18
|
end
|
@@ -26,20 +21,25 @@ module Formulario
|
|
26
21
|
fields.each(&block)
|
27
22
|
end
|
28
23
|
|
24
|
+
def values
|
25
|
+
map(&:value)
|
26
|
+
end
|
27
|
+
|
29
28
|
private
|
30
29
|
|
31
|
-
def self.build(
|
32
|
-
new Array(
|
33
|
-
|
34
|
-
|
30
|
+
def self.build(raw_values)
|
31
|
+
new( Array(raw_values).map { |raw_value|
|
32
|
+
fields_type.for(raw_value)
|
33
|
+
}
|
34
|
+
)
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.
|
38
|
-
@
|
37
|
+
def self.fields_type
|
38
|
+
@fields_type ||= Field
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.
|
42
|
-
@
|
41
|
+
def self.fields_type=(type)
|
42
|
+
@fields_type = type_for(type)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -9,7 +9,6 @@ module Formulario
|
|
9
9
|
new(raw_value, reasons: reasons)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
def exceptional?
|
14
13
|
true
|
15
14
|
end
|
@@ -26,6 +25,10 @@ module Formulario
|
|
26
25
|
reasons.each(&block)
|
27
26
|
end
|
28
27
|
|
28
|
+
def exceptional_class
|
29
|
+
self.class
|
30
|
+
end
|
31
|
+
|
29
32
|
private
|
30
33
|
|
31
34
|
def initialize(raw_value, reasons: Undefined)
|
@@ -43,7 +46,6 @@ module Formulario
|
|
43
46
|
|
44
47
|
super(value)
|
45
48
|
end
|
46
|
-
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -16,6 +16,10 @@ module Formulario
|
|
16
16
|
:array => Formulario::Field::Collection,
|
17
17
|
}
|
18
18
|
|
19
|
+
def self.type_for(type)
|
20
|
+
TYPES.fetch(type)
|
21
|
+
end
|
22
|
+
|
19
23
|
attr_reader :raw_value
|
20
24
|
|
21
25
|
def self.for(raw_value)
|
@@ -67,6 +71,10 @@ module Formulario
|
|
67
71
|
value == new_other.value
|
68
72
|
end
|
69
73
|
|
74
|
+
def exceptional_class
|
75
|
+
::Formulario::Field::ExceptionalValue
|
76
|
+
end
|
77
|
+
|
70
78
|
private
|
71
79
|
|
72
80
|
def self.build(raw_value)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Formulario
|
2
|
+
class Field
|
3
|
+
class Float < Field
|
4
|
+
private
|
5
|
+
|
6
|
+
def self.build(raw_value)
|
7
|
+
new Float(raw_value)
|
8
|
+
rescue ArgumentError, TypeError => e
|
9
|
+
ExceptionalValue.new(raw_value, reasons: ['needs to represent a float'])
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/formulario/form.rb
CHANGED
@@ -3,23 +3,29 @@ module Formulario
|
|
3
3
|
attr_accessor :model
|
4
4
|
|
5
5
|
def initialize(skip_validations: false, **params)
|
6
|
-
__fields.each do |field_name, **options|
|
6
|
+
self.class.__fields.each do |field_name, **options|
|
7
7
|
send("#{field_name}=", params.delete(field_name))
|
8
8
|
end
|
9
9
|
|
10
10
|
params.each do |k, v|
|
11
|
-
|
11
|
+
if self.respond_to?("#{k}=")
|
12
|
+
send("#{k}=", v)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
__validate! unless skip_validations
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.for(model, **rest)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if model
|
21
|
+
fields = __fields.keys.each_with_object({}) { |field_name, res|
|
22
|
+
res[field_name] = model.send(field_name)
|
23
|
+
}
|
24
|
+
|
25
|
+
new(**fields.merge({model: model, **rest}))
|
26
|
+
else
|
27
|
+
new(**rest)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
def self.default
|
@@ -31,10 +37,6 @@ module Formulario
|
|
31
37
|
new(skip_validations: true, **params)
|
32
38
|
end
|
33
39
|
|
34
|
-
def __fields
|
35
|
-
@__fields ||= {}
|
36
|
-
end
|
37
|
-
|
38
40
|
def params
|
39
41
|
__fields.each_with_object({}) { |field_info, res|
|
40
42
|
field_name = field_info.first
|
@@ -74,12 +76,12 @@ module Formulario
|
|
74
76
|
|
75
77
|
private
|
76
78
|
|
77
|
-
def
|
78
|
-
@
|
79
|
+
def __fields
|
80
|
+
@__fields ||= {}
|
79
81
|
end
|
80
82
|
|
81
|
-
def __fields
|
82
|
-
@
|
83
|
+
def self.__fields
|
84
|
+
@field ||= {}
|
83
85
|
end
|
84
86
|
|
85
87
|
def self.field(field_name,
|
@@ -93,7 +95,12 @@ module Formulario
|
|
93
95
|
validators: [],
|
94
96
|
)
|
95
97
|
|
98
|
+
define_method("__set_field_#{field_name}") do
|
99
|
+
__fields[field_name.to_sym] ||= self.class.__fields[field_name.to_sym].dup
|
100
|
+
end
|
101
|
+
|
96
102
|
define_method(field_name) do
|
103
|
+
send("__set_field_#{field_name}")
|
97
104
|
__fields[field_name.to_sym].value
|
98
105
|
end
|
99
106
|
|
@@ -104,6 +111,7 @@ module Formulario
|
|
104
111
|
end
|
105
112
|
|
106
113
|
define_method("#{field_name}=") do |raw_value|
|
114
|
+
send("__set_field_#{field_name}")
|
107
115
|
__fields[field_name.to_sym].value = Field.type_for(field_type).for(
|
108
116
|
send("set_#{field_name}", raw_value)
|
109
117
|
)
|
data/lib/formulario/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formulario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/formulario/fields/default_time_field.rb
|
124
124
|
- lib/formulario/fields/exceptional_value.rb
|
125
125
|
- lib/formulario/fields/field.rb
|
126
|
+
- lib/formulario/fields/float.rb
|
126
127
|
- lib/formulario/fields/form_field.rb
|
127
128
|
- lib/formulario/fields/id.rb
|
128
129
|
- lib/formulario/fields/integer.rb
|
@@ -140,7 +141,7 @@ metadata:
|
|
140
141
|
homepage_uri: https://gitlab.com/fiachetti/formulario
|
141
142
|
source_code_uri: https://gitlab.com/fiachetti/formulario
|
142
143
|
changelog_uri: https://gitlab.com/fiachetti/formulario/blob/d46f675a18c4fbf1d16634a5da343a648af7cf0c/CHANGELOG.org
|
143
|
-
post_install_message:
|
144
|
+
post_install_message:
|
144
145
|
rdoc_options: []
|
145
146
|
require_paths:
|
146
147
|
- lib
|
@@ -155,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
156
|
- !ruby/object:Gem::Version
|
156
157
|
version: '0'
|
157
158
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
159
|
-
signing_key:
|
159
|
+
rubygems_version: 3.2.3
|
160
|
+
signing_key:
|
160
161
|
specification_version: 4
|
161
162
|
summary: Form objects for your project
|
162
163
|
test_files: []
|