easy_params 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38358431f3a00f55f6a46aaa72941c1cbe0fe5f81d6a2fd898a019e09c2cf069
4
- data.tar.gz: 218c09133f6cc7220545fe2fbdf34deefc8a6ab4941d6ef9e729d264f6ecca93
3
+ metadata.gz: 6c3709594b8141aa9bc0d851a2f1eabcf40b7528637ad3d055c76e3ad7db1ac8
4
+ data.tar.gz: da9839e5b6f8242fe05ad074868fb23a3181840b723333b7fa66f9717efca4d7
5
5
  SHA512:
6
- metadata.gz: 8674d76046f76b6ce08e0e1a7c2a1d8c12f55bf549b4ea580fcfcf1b6a5b50cda6caa6621b684fd94a41a8bad3a25044de5ea2b8b2f68e7496e6dec00e86d3ea
7
- data.tar.gz: 268b513fff84704447102ee24f1cfef76e271c73a7ab7379eef1fc1093307c69d462d0679eb387d85bc90031e588d399b53ba2c233c94829e335efe4abf7eee6
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.3.1)
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.0.6)
13
- activesupport (= 7.0.6)
14
- activesupport (7.0.6)
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
- dry-configurable (0.14.0)
32
+ drb (2.2.0)
33
+ ruby2_keywords
34
+ dry-core (1.0.1)
25
35
  concurrent-ruby (~> 1.0)
26
- dry-core (~> 0.6)
27
- dry-container (0.9.0)
36
+ zeitwerk (~> 2.6)
37
+ dry-inflector (1.0.0)
38
+ dry-logic (1.5.0)
28
39
  concurrent-ruby (~> 1.0)
29
- dry-configurable (~> 0.13, >= 0.13.0)
30
- dry-core (0.7.1)
31
- concurrent-ruby (~> 1.0)
32
- dry-inflector (0.3.0)
33
- dry-logic (1.2.0)
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
- dry-types (1.5.1)
46
+ zeitwerk (~> 2.6)
47
+ dry-types (1.7.2)
48
+ bigdecimal (~> 3.0)
41
49
  concurrent-ruby (~> 1.0)
42
- dry-container (~> 0.3)
43
- dry-core (~> 0.5, >= 0.5)
44
- dry-inflector (~> 0.1, >= 0.1.2)
45
- dry-logic (~> 1.0, >= 1.0.2)
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.18.1)
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
@@ -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
@@ -2,19 +2,18 @@
2
2
 
3
3
  module EasyParams
4
4
  module Types
5
- Struct = EasyParams::Base.meta(omittable: true)
6
- StructDSL = ::Class.new(EasyParams::Base).extend(EasyParams::DSL).meta(omittable: true)
7
- Integer = Dry::Types['params.integer'].optional.meta(omittable: true).default(nil)
8
- Decimal = Dry::Types['params.decimal'].optional.meta(omittable: true).default(nil)
9
- Float = Dry::Types['params.float'].optional.meta(omittable: true).default(nil)
10
- Bool = Dry::Types['strict.bool'].optional.meta(omittable: true).default(nil)
11
- String = Dry::Types['string'].optional.meta(omittable: true).default(nil)
12
- Array = Dry::Types['array'].meta(omittable: true).default([])
13
- Date = Dry::Types['params.date'].optional.meta(omittable: true).default(nil)
14
- DateTime = Dry::Types['params.date_time'].optional.meta(omittable: true).default(nil)
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, StructDSL].freeze
18
- ARRAY_OF_STRUCTS_TYPES_LIST = [Array.of(Struct), Array.of(StructDSL)].freeze
16
+ STRUCT_TYPES_LIST = [Struct].freeze
17
+ ARRAY_OF_STRUCTS_TYPES_LIST = [Array.of(Struct)].freeze
19
18
  end
20
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyParams
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.1'
5
5
  end
data/lib/easy_params.rb CHANGED
@@ -4,7 +4,6 @@ require 'dry-struct'
4
4
  require 'dry-types'
5
5
  require 'active_model'
6
6
  require 'easy_params/base'
7
- require 'easy_params/dsl'
8
7
  require 'easy_params/types'
9
8
  require 'easy_params/version'
10
9
 
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.3.1
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: 2023-07-28 00:00:00.000000000 Z
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
@@ -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