easy_params 0.3.1 → 0.4.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 +4 -4
- data/Gemfile.lock +34 -23
- data/lib/easy_params/base.rb +38 -4
- data/lib/easy_params/types.rb +12 -13
- data/lib/easy_params/version.rb +1 -1
- data/lib/easy_params.rb +0 -1
- metadata +2 -3
- data/lib/easy_params/dsl.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c3709594b8141aa9bc0d851a2f1eabcf40b7528637ad3d055c76e3ad7db1ac8
|
4
|
+
data.tar.gz: da9839e5b6f8242fe05ad074868fb23a3181840b723333b7fa66f9717efca4d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 784db4e629c9800db787546346c9dd555ec277f578ecebfa9d59d5d76bb0532612d04a9e711b0f76a5040c9257673bf9e2c97ca85cb47bb1addeb67b7549310d
|
7
|
+
data.tar.gz: 20ced440392006961a46feab7eea99b2a71dc752dbf4f04559041f5fb9f7aa861524faec9d50cab56b3c13ca29dff7ec9dd192012289ed84061485a7ad1f094a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
easy_params (0.
|
4
|
+
easy_params (0.4.1)
|
5
5
|
activemodel (>= 3.2, < 8)
|
6
6
|
dry-struct (~> 1.4)
|
7
7
|
dry-types (~> 1.5)
|
@@ -9,46 +9,55 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activemodel (7.
|
13
|
-
activesupport (= 7.
|
14
|
-
activesupport (7.
|
12
|
+
activemodel (7.1.2)
|
13
|
+
activesupport (= 7.1.2)
|
14
|
+
activesupport (7.1.2)
|
15
|
+
base64
|
16
|
+
bigdecimal
|
15
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
connection_pool (>= 2.2.5)
|
19
|
+
drb
|
16
20
|
i18n (>= 1.6, < 2)
|
17
21
|
minitest (>= 5.1)
|
22
|
+
mutex_m
|
18
23
|
tzinfo (~> 2.0)
|
19
24
|
ast (2.4.2)
|
25
|
+
base64 (0.2.0)
|
26
|
+
bigdecimal (3.1.5)
|
20
27
|
coderay (1.1.3)
|
21
28
|
concurrent-ruby (1.2.2)
|
29
|
+
connection_pool (2.4.1)
|
22
30
|
diff-lcs (1.4.4)
|
23
31
|
docile (1.3.5)
|
24
|
-
|
32
|
+
drb (2.2.0)
|
33
|
+
ruby2_keywords
|
34
|
+
dry-core (1.0.1)
|
25
35
|
concurrent-ruby (~> 1.0)
|
26
|
-
|
27
|
-
dry-
|
36
|
+
zeitwerk (~> 2.6)
|
37
|
+
dry-inflector (1.0.0)
|
38
|
+
dry-logic (1.5.0)
|
28
39
|
concurrent-ruby (~> 1.0)
|
29
|
-
dry-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
concurrent-ruby (~> 1.0)
|
35
|
-
dry-core (~> 0.5, >= 0.5)
|
36
|
-
dry-struct (1.4.0)
|
37
|
-
dry-core (~> 0.5, >= 0.5)
|
38
|
-
dry-types (~> 1.5)
|
40
|
+
dry-core (~> 1.0, < 2)
|
41
|
+
zeitwerk (~> 2.6)
|
42
|
+
dry-struct (1.6.0)
|
43
|
+
dry-core (~> 1.0, < 2)
|
44
|
+
dry-types (>= 1.7, < 2)
|
39
45
|
ice_nine (~> 0.11)
|
40
|
-
|
46
|
+
zeitwerk (~> 2.6)
|
47
|
+
dry-types (1.7.2)
|
48
|
+
bigdecimal (~> 3.0)
|
41
49
|
concurrent-ruby (~> 1.0)
|
42
|
-
dry-
|
43
|
-
dry-
|
44
|
-
dry-
|
45
|
-
|
50
|
+
dry-core (~> 1.0)
|
51
|
+
dry-inflector (~> 1.0)
|
52
|
+
dry-logic (~> 1.4)
|
53
|
+
zeitwerk (~> 2.6)
|
46
54
|
i18n (1.14.1)
|
47
55
|
concurrent-ruby (~> 1.0)
|
48
56
|
ice_nine (0.11.2)
|
49
57
|
json (2.6.3)
|
50
58
|
method_source (1.0.0)
|
51
|
-
minitest (5.
|
59
|
+
minitest (5.21.1)
|
60
|
+
mutex_m (0.2.0)
|
52
61
|
parallel (1.23.0)
|
53
62
|
parser (3.2.2.3)
|
54
63
|
ast (~> 2.4.1)
|
@@ -89,6 +98,7 @@ GEM
|
|
89
98
|
rubocop-ast (1.29.0)
|
90
99
|
parser (>= 3.2.1.0)
|
91
100
|
ruby-progressbar (1.13.0)
|
101
|
+
ruby2_keywords (0.0.5)
|
92
102
|
simplecov (0.21.2)
|
93
103
|
docile (~> 1.1)
|
94
104
|
simplecov-html (~> 0.11)
|
@@ -98,6 +108,7 @@ GEM
|
|
98
108
|
tzinfo (2.0.6)
|
99
109
|
concurrent-ruby (~> 1.0)
|
100
110
|
unicode-display_width (2.4.2)
|
111
|
+
zeitwerk (2.6.12)
|
101
112
|
|
102
113
|
PLATFORMS
|
103
114
|
ruby
|
data/lib/easy_params/base.rb
CHANGED
@@ -11,14 +11,48 @@ module EasyParams
|
|
11
11
|
'EasyParams::Base'
|
12
12
|
end
|
13
13
|
|
14
|
-
%w[Integer Decimal Float Bool String Array Date DateTime Time Struct StructDSL].each do |type|
|
15
|
-
send(:define_singleton_method, type.underscore) { EasyParams::Types.const_get(type) }
|
16
|
-
end
|
17
|
-
|
18
14
|
validate do
|
19
15
|
validate_nested
|
20
16
|
end
|
21
17
|
|
18
|
+
# %w[Integer Decimal Float Bool String Date DateTime Time Array Struct StructDSL].each do |type|
|
19
|
+
%w[Integer Decimal Float Bool String Date DateTime Time].each do |type_name|
|
20
|
+
send(:define_singleton_method,
|
21
|
+
type_name.underscore) do |param_name, default: nil, normalize: nil, optional: nil, **validations|
|
22
|
+
type = EasyParams::Types.const_get(type_name)
|
23
|
+
type = type.default(default) if default
|
24
|
+
type = type.meta(omittable: true) if optional
|
25
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
26
|
+
validates param_name, **validations if validations.any?
|
27
|
+
public_send(:attribute, param_name, type)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.each(param_name, normalize: nil, optional: nil, **validations, &block)
|
32
|
+
validates param_name, **validations if validations.any?
|
33
|
+
type = EasyParams::Types::Array.of(EasyParams::Types::Struct)
|
34
|
+
type = type.meta(omittable: true) if optional
|
35
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
36
|
+
public_send(:attribute, param_name, type, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.has(param_name, normalize: nil, optional: nil, **validations, &block)
|
40
|
+
validates param_name, **validations if validations.any?
|
41
|
+
type = EasyParams::Types::Struct
|
42
|
+
type = type.meta(omittable: true) if optional
|
43
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
44
|
+
public_send(:attribute, param_name, type, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.array(param_name, of:, normalize: nil, optional: nil, **validations, &block)
|
48
|
+
validates param_name, **validations if validations.any?
|
49
|
+
of_type = EasyParams::Types.const_get(of.to_s.camelcase)
|
50
|
+
type = EasyParams::Types::Array
|
51
|
+
type = type.meta(omittable: true) if optional
|
52
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
53
|
+
public_send(:attribute, param_name, type.of(of_type), &block)
|
54
|
+
end
|
55
|
+
|
22
56
|
private
|
23
57
|
|
24
58
|
def validate_nested
|
data/lib/easy_params/types.rb
CHANGED
@@ -2,19 +2,18 @@
|
|
2
2
|
|
3
3
|
module EasyParams
|
4
4
|
module Types
|
5
|
-
Struct = EasyParams::Base
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Time = Dry::Types['params.time'].optional.meta(omittable: true).default(nil)
|
5
|
+
Struct = EasyParams::Base
|
6
|
+
Integer = Dry::Types['params.integer'].optional.default(nil)
|
7
|
+
Decimal = Dry::Types['params.decimal'].optional.default(nil)
|
8
|
+
Float = Dry::Types['params.float'].optional.default(nil)
|
9
|
+
Bool = Dry::Types['params.bool'].optional.default(nil)
|
10
|
+
String = Dry::Types['coercible.string'].optional.default(nil)
|
11
|
+
Array = Dry::Types['array'].default([].freeze)
|
12
|
+
Date = Dry::Types['params.date'].optional.default(nil)
|
13
|
+
DateTime = Dry::Types['params.date_time'].optional.default(nil)
|
14
|
+
Time = Dry::Types['params.time'].optional.default(nil)
|
16
15
|
|
17
|
-
STRUCT_TYPES_LIST = [Struct
|
18
|
-
ARRAY_OF_STRUCTS_TYPES_LIST = [Array.of(Struct)
|
16
|
+
STRUCT_TYPES_LIST = [Struct].freeze
|
17
|
+
ARRAY_OF_STRUCTS_TYPES_LIST = [Array.of(Struct)].freeze
|
19
18
|
end
|
20
19
|
end
|
data/lib/easy_params/version.rb
CHANGED
data/lib/easy_params.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrii Baran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- easy_params.gemspec
|
83
83
|
- lib/easy_params.rb
|
84
84
|
- lib/easy_params/base.rb
|
85
|
-
- lib/easy_params/dsl.rb
|
86
85
|
- lib/easy_params/types.rb
|
87
86
|
- lib/easy_params/version.rb
|
88
87
|
homepage: https://github.com/andriy-baran/easy_params
|
data/lib/easy_params/dsl.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EasyParams
|
4
|
-
# Makes definition more compact
|
5
|
-
# Do not use if your attributes have name like
|
6
|
-
# integer, decimal, float, bool, string, array, date, datetime, time, struct
|
7
|
-
module DSL
|
8
|
-
def each(&block)
|
9
|
-
array.of(struct_dsl, &block)
|
10
|
-
end
|
11
|
-
|
12
|
-
def has(&block)
|
13
|
-
struct_dsl(&block)
|
14
|
-
end
|
15
|
-
|
16
|
-
def method_missing(method_name, *args, &block)
|
17
|
-
public_send(:attribute, method_name, *args, &block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def respond_to_missing?(*)
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|