params_ready 0.0.2 → 0.0.5

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: 6e0db6411b802c544350d14eb54c921ae019ac7b2365fc2639b4f2f1b77ee40a
4
- data.tar.gz: 3811299181627e888b1ac97970a4264f850db87f0475be355a138a30aa825eb1
3
+ metadata.gz: 3fe16e13531ab2ae207b8656a5daf5e71ad4db06adf638936e5a4f80803dc0a8
4
+ data.tar.gz: 0357fb20e9c206e68a257936760d8d20c1c9fdf863c61f50d730d29340362742
5
5
  SHA512:
6
- metadata.gz: f2f339b6dd2a649244d53c94168ad3e3b238a42268632175c08c3928e01861d75c5c19d7fc3c29b8e0482e8658ed6e5f3a17d9ccda34d0b63808b5e1538b4870
7
- data.tar.gz: 355252607fd9c47d58acf4cf1176bc5d35677390bbfeecfe1e24d881f9303be23d20dbcc8611b9c4cff25ff277944e0a2ad9e85aef7ccf0e7174a0a02856f1c3
6
+ metadata.gz: bd90dfe134db52a495589a8a56245be744e20239285afef6a04dc38f47337ecdadcbf02a758391e936d48654da3ffd9b72a938654aec05a3b9cc19390240bdf5
7
+ data.tar.gz: 2389b613a4fe45e2fb32cc2469da23b761e670e6af9d5305758caa52254a66545237606046955d8ec848f4a58aea2e27c8b878f281fbecbd9e0064edc899d9d7
data/lib/params_ready.rb CHANGED
@@ -28,7 +28,7 @@ require_relative 'params_ready/query/variable_operator_predicate'
28
28
 
29
29
 
30
30
  module ParamsReady
31
- VERSION = '0.0.2'.freeze
31
+ VERSION = '0.0.5'.freeze
32
32
 
33
33
  def self.gem_version
34
34
  ::Gem::Version.new(VERSION)
@@ -70,28 +70,32 @@ module ParamsReady
70
70
  builder_class.register name
71
71
  end
72
72
 
73
- def self.instance(name, coder_or_name = nil, altn: nil)
73
+ def self.instance(name, coder_or_name = nil, altn: nil, **opts)
74
74
  coder = if coder_or_name.is_a? Symbol
75
- self.coder(coder_or_name)
76
- elsif coder_or_name.nil?
77
- Value::GenericCoder.new(name)
75
+ coder_class = self.coder(coder_or_name)
76
+ coder_class.instance(**opts)
78
77
  else
79
- coder_or_name
78
+ raise ParamsReadyError, 'Expected option hash to be empty' unless opts.empty?
79
+ if coder_or_name.nil?
80
+ Value::GenericCoder.new(name)
81
+ else
82
+ coder_or_name
83
+ end
80
84
  end
81
85
  new ValueParameterDefinition.new(name, coder, altn: altn)
82
86
  end
83
87
 
84
- def self.[](type)
88
+ def self.[](coder_name)
85
89
  builder = Class.new(self)
86
- capitalized = type.to_s.split('_').map(&:capitalize).join
90
+ capitalized = coder_name.to_s.split('_').map(&:capitalize).join
87
91
  qualified = "#{self.name}::#{capitalized}Builder".freeze
88
92
 
89
93
  builder.define_singleton_method :name do
90
94
  qualified
91
95
  end
92
96
 
93
- builder.define_singleton_method :instance do |name, altn: nil|
94
- superclass.instance(name, type, altn: altn)
97
+ builder.define_singleton_method :instance do |name, altn: nil, **opts|
98
+ superclass.instance(name, coder_name, altn: altn, **opts)
95
99
  end
96
100
 
97
101
  builder
@@ -18,9 +18,8 @@ module ParamsReady
18
18
  end
19
19
  end
20
20
 
21
- class Coder
21
+ class AbstractCoder
22
22
  extend Extensions::ClassReaderWriter
23
- extend Coercion
24
23
 
25
24
  def self.value_class_name
26
25
  last = self.name.split("::").last
@@ -31,10 +30,38 @@ module ParamsReady
31
30
  type_identifier :value
32
31
  end
33
32
 
33
+ class Coder < AbstractCoder
34
+ extend Coercion
35
+
36
+ def self.instance(**opts)
37
+ raise ParamsReadyError, "No options expected, got: #{opts}" unless opts.empty?
38
+
39
+ self
40
+ end
41
+
42
+ class Instantiable < AbstractCoder
43
+ include Coercion
44
+
45
+ def self.instance(**opts)
46
+ new **opts
47
+ end
48
+
49
+ def type_identifier
50
+ self.class.type_identifier
51
+ end
52
+
53
+ def strict_default?
54
+ self.class.strict_default?
55
+ end
56
+ end
57
+ end
58
+
59
+
34
60
  class GenericCoder
35
61
  extend Extensions::LateInit
36
62
  extend Extensions::Finalizer
37
63
  include Extensions::Finalizer::InstanceMethods
64
+ include Coercion
38
65
 
39
66
  def initialize(name)
40
67
  @name = name
@@ -43,8 +70,6 @@ module ParamsReady
43
70
  @type_identifier = nil
44
71
  end
45
72
 
46
- def strict_default?; true; end
47
-
48
73
  late_init(:coerce, getter: false)
49
74
  late_init(:format, getter: false)
50
75
  late_init(:type_identifier, obligatory: false)
@@ -53,10 +78,8 @@ module ParamsReady
53
78
  @name
54
79
  end
55
80
 
56
- def try_coerce(input, context)
81
+ def coerce(input, context)
57
82
  @coerce[input, context]
58
- rescue => _error
59
- raise CoercionError.new(input, @name)
60
83
  end
61
84
 
62
85
  def format(value, format)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: params_ready
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Milsimer
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '6'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -66,9 +66,52 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
- description: "Create well defined controller interfaces. Preprocess, coerce and constrain
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-rg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.20'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.20'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1'
111
+ description: "Create well defined controller interfaces. Sanitize, coerce and constrain
70
112
  \nincoming parameters to safely populate data models, hold session state in URI
71
- variables \nacross different locations, build SQL queries.\n"
113
+ variables \nacross different locations, build SQL queries, apply ordering and offset/keyset
114
+ pagination.\n"
72
115
  email: tomas.milsimer@protonmail.com
73
116
  executables: []
74
117
  extensions: []
@@ -174,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
217
  - !ruby/object:Gem::Version
175
218
  version: '0'
176
219
  requirements: []
177
- rubygems_version: 3.1.2
220
+ rubygems_version: 3.0.3
178
221
  signing_key:
179
222
  specification_version: 4
180
223
  summary: Define controller interfaces in Rails