easy_params 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -23
- data/lib/easy_params/base.rb +41 -4
- data/lib/easy_params/types.rb +5 -4
- 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: 8a23a79fb06b0d9c02b836dc314e420f1339b20473d740f4427a6f1a9e740efe
|
4
|
+
data.tar.gz: e1ddbee8e7b5aa08fb3e9f1f2dc925ecc179a8f95ac3276e2aeb839f7e3cbe9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a9968cc2201493bd774562cc9590d47537b870238ac5b64b33167c9b084feb14c067b6b4ee9a36f54abdff18a198c8d99474b8dc531fab45ebbffd61ae08c11
|
7
|
+
data.tar.gz: 11d7e883cc4a229c14b9323e94f8372e2f38d2c238e883884c2fe733bab4918be6ad62c13da09621fbb0e8b5b85405d7d2d9cb8197abc3cbf0d762b6657c2a7d
|
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.0)
|
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.20.0)
|
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,51 @@ 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, type_name.underscore) do |param_name, default: nil, normalize: nil, **validations|
|
21
|
+
type = EasyParams::Types.const_get(type_name)
|
22
|
+
type = type.default(default) if default
|
23
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
24
|
+
validates param_name, **validations if validations.any?
|
25
|
+
public_send(:attribute, param_name, type)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.each(param_name, normalize: nil, **validations, &block)
|
30
|
+
validates param_name, **validations if validations.any?
|
31
|
+
type = EasyParams::Types::Each
|
32
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
33
|
+
public_send(:attribute, param_name, type, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.has(param_name, normalize: nil, **validations, &block)
|
37
|
+
validates param_name, **validations if validations.any?
|
38
|
+
type = EasyParams::Types::Struct
|
39
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
40
|
+
public_send(:attribute, param_name, type, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.array(param_name, of:, normalize: nil, **validations, &block)
|
44
|
+
validates param_name, **validations if validations.any?
|
45
|
+
of_type = EasyParams::Types.const_get(of.to_s.camelcase)
|
46
|
+
type = EasyParams::Types::Array
|
47
|
+
type = type.constructor { |value| value == Dry::Types::Undefined ? value : normalize.call(value) } if normalize
|
48
|
+
public_send(:attribute, param_name, type.of(of_type), &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.param(method_name, type_name, of: nil, default: nil, **validations, &block)
|
52
|
+
type = EasyParams::Types.const_get(type_name.to_s.camelcase)
|
53
|
+
type = type.default(default) if default
|
54
|
+
type = type.of(EasyParams::Types.const_get(of.to_s.camelcase)) if of && type_name != :each
|
55
|
+
validates method_name, **validations if validations.any?
|
56
|
+
public_send(:attribute, method_name, type, &block)
|
57
|
+
end
|
58
|
+
|
22
59
|
private
|
23
60
|
|
24
61
|
def validate_nested
|
data/lib/easy_params/types.rb
CHANGED
@@ -3,18 +3,19 @@
|
|
3
3
|
module EasyParams
|
4
4
|
module Types
|
5
5
|
Struct = EasyParams::Base.meta(omittable: true)
|
6
|
-
|
6
|
+
Has = EasyParams::Base.meta(omittable: true)
|
7
7
|
Integer = Dry::Types['params.integer'].optional.meta(omittable: true).default(nil)
|
8
8
|
Decimal = Dry::Types['params.decimal'].optional.meta(omittable: true).default(nil)
|
9
9
|
Float = Dry::Types['params.float'].optional.meta(omittable: true).default(nil)
|
10
|
-
Bool = Dry::Types['
|
10
|
+
Bool = Dry::Types['params.bool'].optional.meta(omittable: true).default(nil)
|
11
11
|
String = Dry::Types['string'].optional.meta(omittable: true).default(nil)
|
12
12
|
Array = Dry::Types['array'].meta(omittable: true).default([])
|
13
|
+
Each = Dry::Types['array'].of(Struct).meta(omittable: true).default([])
|
13
14
|
Date = Dry::Types['params.date'].optional.meta(omittable: true).default(nil)
|
14
15
|
DateTime = Dry::Types['params.date_time'].optional.meta(omittable: true).default(nil)
|
15
16
|
Time = Dry::Types['params.time'].optional.meta(omittable: true).default(nil)
|
16
17
|
|
17
|
-
STRUCT_TYPES_LIST = [Struct,
|
18
|
-
ARRAY_OF_STRUCTS_TYPES_LIST = [Array.of(Struct),
|
18
|
+
STRUCT_TYPES_LIST = [Struct, Has].freeze
|
19
|
+
ARRAY_OF_STRUCTS_TYPES_LIST = [Array.of(Struct), Each].freeze
|
19
20
|
end
|
20
21
|
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.0
|
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-08 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
|