castkit 0.3.0 → 0.4.0
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/CHANGELOG.md +44 -0
- data/README.md +19 -11
- data/castkit.gemspec +4 -0
- data/lib/castkit/attribute.rb +87 -65
- data/lib/castkit/attributes/definition.rb +64 -0
- data/lib/castkit/attributes/options.rb +214 -0
- data/lib/castkit/castkit.rb +14 -3
- data/lib/castkit/cli/generate.rb +14 -0
- data/lib/castkit/configuration.rb +25 -48
- data/lib/castkit/contract/base.rb +8 -23
- data/lib/castkit/contract/result.rb +10 -6
- data/lib/castkit/contract/validator.rb +5 -1
- data/lib/castkit/core/attribute_types.rb +3 -1
- data/lib/castkit/core/attributes.rb +132 -65
- data/lib/castkit/core/config.rb +23 -13
- data/lib/castkit/data_object.rb +9 -29
- data/lib/castkit/{ext → dsl}/attribute/access.rb +1 -1
- data/lib/castkit/{ext → dsl}/attribute/error_handling.rb +1 -1
- data/lib/castkit/{ext → dsl}/attribute/options.rb +1 -1
- data/lib/castkit/{ext → dsl}/attribute/validation.rb +3 -3
- data/lib/castkit/dsl/attribute.rb +47 -0
- data/lib/castkit/{ext → dsl}/data_object/contract.rb +1 -1
- data/lib/castkit/{ext → dsl}/data_object/deserialization.rb +24 -3
- data/lib/castkit/dsl/data_object/introspection.rb +52 -0
- data/lib/castkit/{ext → dsl}/data_object/plugins.rb +1 -1
- data/lib/castkit/{ext → dsl}/data_object/serialization.rb +5 -2
- data/lib/castkit/dsl/data_object.rb +65 -0
- data/lib/castkit/error.rb +8 -4
- data/lib/castkit/plugins.rb +12 -3
- data/lib/castkit/serializers/base.rb +9 -4
- data/lib/castkit/serializers/default_serializer.rb +10 -10
- data/lib/castkit/types/base.rb +24 -3
- data/lib/castkit/validators/boolean_validator.rb +3 -3
- data/lib/castkit/validators/collection_validator.rb +2 -2
- data/lib/castkit/version.rb +1 -1
- data/lib/castkit.rb +1 -4
- data/lib/generators/attribute.rb +39 -0
- data/lib/generators/templates/attribute.rb.tt +21 -0
- data/lib/generators/templates/attribute_spec.rb.tt +41 -0
- data/lib/generators/templates/contract.rb.tt +2 -0
- data/lib/generators/templates/data_object.rb.tt +2 -0
- data/lib/generators/templates/type.rb.tt +2 -0
- data/lib/generators/templates/validator.rb.tt +1 -1
- metadata +74 -12
- data/.rspec_status +0 -195
- data/lib/castkit/core/registerable.rb +0 -59
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "thor/group"
|
|
4
|
+
require "castkit/inflector"
|
|
5
|
+
require_relative "base"
|
|
6
|
+
|
|
7
|
+
module Castkit
|
|
8
|
+
module Generators
|
|
9
|
+
# Generator for creating Castkit attribute definitions.
|
|
10
|
+
#
|
|
11
|
+
# Generates a class inheriting from `Castkit::Attributes::Definition`
|
|
12
|
+
# and an optional spec file.
|
|
13
|
+
#
|
|
14
|
+
# Example:
|
|
15
|
+
# $ castkit generate attribute OptionalString required:false default:"N/A"
|
|
16
|
+
#
|
|
17
|
+
# This will generate:
|
|
18
|
+
# - lib/castkit/attributes/optional_string.rb
|
|
19
|
+
# - spec/castkit/attributes/optional_string_spec.rb
|
|
20
|
+
#
|
|
21
|
+
# @see Castkit::Generators::Base
|
|
22
|
+
class Attribute < Castkit::Generators::Base
|
|
23
|
+
component :attribute
|
|
24
|
+
|
|
25
|
+
argument :type,
|
|
26
|
+
type: :string,
|
|
27
|
+
desc: "The base type (e.g., string, integer)"
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# @return [Hash] configuration passed into templates
|
|
32
|
+
def config
|
|
33
|
+
super.merge(
|
|
34
|
+
type: type.first.gsub(/^:/, "")
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "castkit/attributes/definition"
|
|
4
|
+
|
|
5
|
+
module Castkit
|
|
6
|
+
module Attributes
|
|
7
|
+
# Attribute definition for <%= config[:class_name] %>.
|
|
8
|
+
#
|
|
9
|
+
# This definition can be reused across DataObjects to avoid repeating shared options.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# class UserDto < Castkit::DataObject
|
|
13
|
+
# include Castkit::Attributes
|
|
14
|
+
#
|
|
15
|
+
# attribute :name, using: <%= config[:class_name] %>
|
|
16
|
+
# end
|
|
17
|
+
class <%= config[:class_name] %> < Castkit::Attributes::Definition
|
|
18
|
+
<% if config[:type].empty? %># type :string<% else %>type :<%= config[:type] %><% end %>
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "castkit/attributes/<%= config[:name] %>"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Castkit::Attributes::<%= config[:class_name] %> do
|
|
7
|
+
subject(:attribute) { described_class }
|
|
8
|
+
|
|
9
|
+
let(:type) { attribute.definition[:type] }
|
|
10
|
+
let(:options) { attribute.definition[:options] }
|
|
11
|
+
|
|
12
|
+
describe ".definition" do
|
|
13
|
+
it "returns a valid definition" do
|
|
14
|
+
expect(type).to be_a(Symbol).or be_a(Class)
|
|
15
|
+
expect(options).to be_a(Hash)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "defined type" do
|
|
20
|
+
it "returns defined type" do
|
|
21
|
+
expect(type).to eq(:<%= config[:type] %>)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "defined options" do
|
|
26
|
+
it "includes expected keys" do
|
|
27
|
+
expect(options.keys).to all(be_a(Symbol))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "includes known default keys" do
|
|
31
|
+
expect(options.keys).to include(:required, :access)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "DSL behavior" do
|
|
36
|
+
it "overrides required and access values" do
|
|
37
|
+
expect(options[:required]).to be(true)
|
|
38
|
+
expect(options[:access]).to eq(%i[read write])
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: castkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Lucas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-12-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: cattri
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.2.3
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.2.3
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: thor
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,6 +66,48 @@ dependencies:
|
|
|
52
66
|
- - ">="
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
68
|
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: simplecov
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: simplecov-cobertura
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: simplecov-html
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
55
111
|
- !ruby/object:Gem::Dependency
|
|
56
112
|
name: yard
|
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -76,7 +132,6 @@ extensions: []
|
|
|
76
132
|
extra_rdoc_files: []
|
|
77
133
|
files:
|
|
78
134
|
- ".rspec"
|
|
79
|
-
- ".rspec_status"
|
|
80
135
|
- ".rubocop.yml"
|
|
81
136
|
- CHANGELOG.md
|
|
82
137
|
- CODE_OF_CONDUCT.md
|
|
@@ -86,6 +141,8 @@ files:
|
|
|
86
141
|
- castkit.gemspec
|
|
87
142
|
- lib/castkit.rb
|
|
88
143
|
- lib/castkit/attribute.rb
|
|
144
|
+
- lib/castkit/attributes/definition.rb
|
|
145
|
+
- lib/castkit/attributes/options.rb
|
|
89
146
|
- lib/castkit/castkit.rb
|
|
90
147
|
- lib/castkit/cli.rb
|
|
91
148
|
- lib/castkit/cli/generate.rb
|
|
@@ -100,17 +157,19 @@ files:
|
|
|
100
157
|
- lib/castkit/core/attribute_types.rb
|
|
101
158
|
- lib/castkit/core/attributes.rb
|
|
102
159
|
- lib/castkit/core/config.rb
|
|
103
|
-
- lib/castkit/core/registerable.rb
|
|
104
160
|
- lib/castkit/data_object.rb
|
|
161
|
+
- lib/castkit/dsl/attribute.rb
|
|
162
|
+
- lib/castkit/dsl/attribute/access.rb
|
|
163
|
+
- lib/castkit/dsl/attribute/error_handling.rb
|
|
164
|
+
- lib/castkit/dsl/attribute/options.rb
|
|
165
|
+
- lib/castkit/dsl/attribute/validation.rb
|
|
166
|
+
- lib/castkit/dsl/data_object.rb
|
|
167
|
+
- lib/castkit/dsl/data_object/contract.rb
|
|
168
|
+
- lib/castkit/dsl/data_object/deserialization.rb
|
|
169
|
+
- lib/castkit/dsl/data_object/introspection.rb
|
|
170
|
+
- lib/castkit/dsl/data_object/plugins.rb
|
|
171
|
+
- lib/castkit/dsl/data_object/serialization.rb
|
|
105
172
|
- lib/castkit/error.rb
|
|
106
|
-
- lib/castkit/ext/attribute/access.rb
|
|
107
|
-
- lib/castkit/ext/attribute/error_handling.rb
|
|
108
|
-
- lib/castkit/ext/attribute/options.rb
|
|
109
|
-
- lib/castkit/ext/attribute/validation.rb
|
|
110
|
-
- lib/castkit/ext/data_object/contract.rb
|
|
111
|
-
- lib/castkit/ext/data_object/deserialization.rb
|
|
112
|
-
- lib/castkit/ext/data_object/plugins.rb
|
|
113
|
-
- lib/castkit/ext/data_object/serialization.rb
|
|
114
173
|
- lib/castkit/inflector.rb
|
|
115
174
|
- lib/castkit/plugins.rb
|
|
116
175
|
- lib/castkit/serializers/base.rb
|
|
@@ -133,11 +192,14 @@ files:
|
|
|
133
192
|
- lib/castkit/validators/numeric_validator.rb
|
|
134
193
|
- lib/castkit/validators/string_validator.rb
|
|
135
194
|
- lib/castkit/version.rb
|
|
195
|
+
- lib/generators/attribute.rb
|
|
136
196
|
- lib/generators/base.rb
|
|
137
197
|
- lib/generators/contract.rb
|
|
138
198
|
- lib/generators/data_object.rb
|
|
139
199
|
- lib/generators/plugin.rb
|
|
140
200
|
- lib/generators/serializer.rb
|
|
201
|
+
- lib/generators/templates/attribute.rb.tt
|
|
202
|
+
- lib/generators/templates/attribute_spec.rb.tt
|
|
141
203
|
- lib/generators/templates/contract.rb.tt
|
|
142
204
|
- lib/generators/templates/contract_spec.rb.tt
|
|
143
205
|
- lib/generators/templates/data_object.rb.tt
|
data/.rspec_status
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
example_id | status | run_time |
|
|
2
|
-
------------------------------------------------------------- | ------ | --------------- |
|
|
3
|
-
./spec/castkit/attribute_spec.rb[1:1:1] | passed | 0.00045 seconds |
|
|
4
|
-
./spec/castkit/attribute_spec.rb[1:1:2] | passed | 0.00004 seconds |
|
|
5
|
-
./spec/castkit/attribute_spec.rb[1:1:3] | passed | 0.00004 seconds |
|
|
6
|
-
./spec/castkit/attribute_spec.rb[1:1:4] | passed | 0.00003 seconds |
|
|
7
|
-
./spec/castkit/attribute_spec.rb[1:2:1] | passed | 0.00096 seconds |
|
|
8
|
-
./spec/castkit/attribute_spec.rb[1:3:1] | passed | 0.00004 seconds |
|
|
9
|
-
./spec/castkit/attribute_spec.rb[1:3:2] | passed | 0.00004 seconds |
|
|
10
|
-
./spec/castkit/attribute_spec.rb[1:3:3] | passed | 0.00003 seconds |
|
|
11
|
-
./spec/castkit/attribute_spec.rb[1:3:4] | passed | 0.00079 seconds |
|
|
12
|
-
./spec/castkit/base_spec.rb[1:1:1] | passed | 0.00007 seconds |
|
|
13
|
-
./spec/castkit/base_spec.rb[1:2:1] | passed | 0.00365 seconds |
|
|
14
|
-
./spec/castkit/base_spec.rb[1:3:1] | passed | 0.00009 seconds |
|
|
15
|
-
./spec/castkit/base_spec.rb[1:3:2] | passed | 0.00006 seconds |
|
|
16
|
-
./spec/castkit/base_spec.rb[1:4:1] | passed | 0.00005 seconds |
|
|
17
|
-
./spec/castkit/contract/validator_spec.rb[1:1:1:1] | passed | 0.00008 seconds |
|
|
18
|
-
./spec/castkit/contract/validator_spec.rb[1:1:2:1] | passed | 0.00038 seconds |
|
|
19
|
-
./spec/castkit/contract/validator_spec.rb[1:1:3:1] | passed | 0.00007 seconds |
|
|
20
|
-
./spec/castkit/contract/validator_spec.rb[1:1:4:1] | passed | 0.00009 seconds |
|
|
21
|
-
./spec/castkit/contract/validator_spec.rb[1:1:5:1] | passed | 0.00008 seconds |
|
|
22
|
-
./spec/castkit/contract_spec.rb[1:1:1] | passed | 0.0003 seconds |
|
|
23
|
-
./spec/castkit/contract_spec.rb[1:1:2] | passed | 0.001 seconds |
|
|
24
|
-
./spec/castkit/contract_spec.rb[1:1:3] | passed | 0.00008 seconds |
|
|
25
|
-
./spec/castkit/contract_spec.rb[1:1:4] | passed | 0.00006 seconds |
|
|
26
|
-
./spec/castkit/contract_spec.rb[1:1:5] | passed | 0.00006 seconds |
|
|
27
|
-
./spec/castkit/contract_spec.rb[1:1:6] | passed | 0.00006 seconds |
|
|
28
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:1] | passed | 0.00005 seconds |
|
|
29
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:2] | passed | 0.00003 seconds |
|
|
30
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:3] | passed | 0.00003 seconds |
|
|
31
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:4] | passed | 0.00003 seconds |
|
|
32
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:5] | passed | 0.00003 seconds |
|
|
33
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:6] | passed | 0.00003 seconds |
|
|
34
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:7] | passed | 0.00003 seconds |
|
|
35
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:8] | passed | 0.00006 seconds |
|
|
36
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:9] | passed | 0.00004 seconds |
|
|
37
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:10] | passed | 0.00005 seconds |
|
|
38
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:11] | passed | 0.00003 seconds |
|
|
39
|
-
./spec/castkit/core/attribute_types_spec.rb[1:1:12] | passed | 0.00003 seconds |
|
|
40
|
-
./spec/castkit/core/attributes_spec.rb[1:1:1] | passed | 0.00005 seconds |
|
|
41
|
-
./spec/castkit/core/attributes_spec.rb[1:1:2] | passed | 0.00005 seconds |
|
|
42
|
-
./spec/castkit/core/attributes_spec.rb[1:1:3] | passed | 0.00005 seconds |
|
|
43
|
-
./spec/castkit/core/attributes_spec.rb[1:2:1] | passed | 0.00004 seconds |
|
|
44
|
-
./spec/castkit/core/attributes_spec.rb[1:3:1] | passed | 0.00005 seconds |
|
|
45
|
-
./spec/castkit/core/attributes_spec.rb[1:4:1] | passed | 0.00056 seconds |
|
|
46
|
-
./spec/castkit/core/attributes_spec.rb[1:5:1] | passed | 0.00005 seconds |
|
|
47
|
-
./spec/castkit/core/attributes_spec.rb[1:6:1] | passed | 0.00028 seconds |
|
|
48
|
-
./spec/castkit/core/attributes_spec.rb[1:7:1] | passed | 0.00005 seconds |
|
|
49
|
-
./spec/castkit/core/config_spec.rb[1:1:1] | passed | 0.00003 seconds |
|
|
50
|
-
./spec/castkit/core/config_spec.rb[1:1:2] | passed | 0.00003 seconds |
|
|
51
|
-
./spec/castkit/core/config_spec.rb[1:2:1] | passed | 0.00003 seconds |
|
|
52
|
-
./spec/castkit/core/config_spec.rb[1:3:1] | passed | 0.00003 seconds |
|
|
53
|
-
./spec/castkit/core/config_spec.rb[1:3:2] | passed | 0.00003 seconds |
|
|
54
|
-
./spec/castkit/core/config_spec.rb[1:4:1] | passed | 0.00003 seconds |
|
|
55
|
-
./spec/castkit/core/config_spec.rb[1:4:2] | passed | 0.00003 seconds |
|
|
56
|
-
./spec/castkit/core/config_spec.rb[1:5:1] | passed | 0.00004 seconds |
|
|
57
|
-
./spec/castkit/core/config_spec.rb[1:5:2] | passed | 0.00003 seconds |
|
|
58
|
-
./spec/castkit/data_object_spec.rb[1:1:1] | passed | 0.00094 seconds |
|
|
59
|
-
./spec/castkit/data_object_spec.rb[1:1:2] | passed | 0.00022 seconds |
|
|
60
|
-
./spec/castkit/data_object_spec.rb[1:2:1] | passed | 0.00014 seconds |
|
|
61
|
-
./spec/castkit/data_object_spec.rb[1:2:2] | passed | 0.00174 seconds |
|
|
62
|
-
./spec/castkit/data_object_spec.rb[1:2:3] | passed | 0.0001 seconds |
|
|
63
|
-
./spec/castkit/data_object_spec.rb[1:3:1] | passed | 0.00008 seconds |
|
|
64
|
-
./spec/castkit/data_object_spec.rb[1:3:2] | passed | 0.00008 seconds |
|
|
65
|
-
./spec/castkit/data_object_spec.rb[1:4:1] | passed | 0.00021 seconds |
|
|
66
|
-
./spec/castkit/data_object_spec.rb[1:5:1] | passed | 0.00013 seconds |
|
|
67
|
-
./spec/castkit/data_object_spec.rb[1:5:2] | passed | 0.0001 seconds |
|
|
68
|
-
./spec/castkit/data_object_spec.rb[1:5:3] | passed | 0.00012 seconds |
|
|
69
|
-
./spec/castkit/data_object_spec.rb[1:5:4] | passed | 0.0001 seconds |
|
|
70
|
-
./spec/castkit/data_object_spec.rb[1:5:5] | passed | 0.00073 seconds |
|
|
71
|
-
./spec/castkit/data_object_spec.rb[1:5:6] | passed | 0.00015 seconds |
|
|
72
|
-
./spec/castkit/data_object_spec.rb[1:5:7] | passed | 0.00011 seconds |
|
|
73
|
-
./spec/castkit/data_object_spec.rb[1:6:1] | passed | 0.0001 seconds |
|
|
74
|
-
./spec/castkit/data_object_spec.rb[1:7:1] | passed | 0.0001 seconds |
|
|
75
|
-
./spec/castkit/data_object_spec.rb[1:8:1] | passed | 0.00021 seconds |
|
|
76
|
-
./spec/castkit/data_object_spec.rb[1:8:2] | passed | 0.00011 seconds |
|
|
77
|
-
./spec/castkit/data_object_spec.rb[1:9:1] | passed | 0.00011 seconds |
|
|
78
|
-
./spec/castkit/default_serializer_spec.rb[1:1:1] | passed | 0.00011 seconds |
|
|
79
|
-
./spec/castkit/default_serializer_spec.rb[1:2:1] | passed | 0.00023 seconds |
|
|
80
|
-
./spec/castkit/default_serializer_spec.rb[1:2:2] | passed | 0.00008 seconds |
|
|
81
|
-
./spec/castkit/default_serializer_spec.rb[1:2:3] | passed | 0.00016 seconds |
|
|
82
|
-
./spec/castkit/default_serializer_spec.rb[1:3:1] | passed | 0.00019 seconds |
|
|
83
|
-
./spec/castkit/default_serializer_spec.rb[1:3:2] | passed | 0.00027 seconds |
|
|
84
|
-
./spec/castkit/default_serializer_spec.rb[1:3:3] | passed | 0.00016 seconds |
|
|
85
|
-
./spec/castkit/default_serializer_spec.rb[1:3:4] | passed | 0.00012 seconds |
|
|
86
|
-
./spec/castkit/default_serializer_spec.rb[1:4:1] | passed | 0.00008 seconds |
|
|
87
|
-
./spec/castkit/default_serializer_spec.rb[1:5:1] | passed | 0.00007 seconds |
|
|
88
|
-
./spec/castkit/default_serializer_spec.rb[1:5:2] | passed | 0.00006 seconds |
|
|
89
|
-
./spec/castkit/default_serializer_spec.rb[1:5:3] | passed | 0.00006 seconds |
|
|
90
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:1:1] | passed | 0.00004 seconds |
|
|
91
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:1:2:1] | passed | 0.00011 seconds |
|
|
92
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
|
|
93
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
|
|
94
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:2:1:1] | passed | 0.00004 seconds |
|
|
95
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:2:2:1] | passed | 0.00004 seconds |
|
|
96
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:2:3:1] | passed | 0.00004 seconds |
|
|
97
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:3:1] | passed | 0.00003 seconds |
|
|
98
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:3:2] | passed | 0.00009 seconds |
|
|
99
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:3:3] | passed | 0.00004 seconds |
|
|
100
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:3:4] | passed | 0.00003 seconds |
|
|
101
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:3:5] | passed | 0.00003 seconds |
|
|
102
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:4:1:1] | passed | 0.00005 seconds |
|
|
103
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:4:2:1] | passed | 0.00004 seconds |
|
|
104
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:4:3:1] | passed | 0.00004 seconds |
|
|
105
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:5:1] | passed | 0.00004 seconds |
|
|
106
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:5:2] | passed | 0.00003 seconds |
|
|
107
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:5:3] | passed | 0.00003 seconds |
|
|
108
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:6:1:1] | passed | 0.00003 seconds |
|
|
109
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:6:2:1] | passed | 0.00003 seconds |
|
|
110
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:6:3:1] | passed | 0.00003 seconds |
|
|
111
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:7:1:1] | passed | 0.00003 seconds |
|
|
112
|
-
./spec/castkit/ext/attribute/access_spec.rb[1:7:2:1] | passed | 0.00003 seconds |
|
|
113
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:1:1:1] | passed | 0.00005 seconds |
|
|
114
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:1:2:1] | passed | 0.00004 seconds |
|
|
115
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:2:1:1] | passed | 0.00004 seconds |
|
|
116
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:2:2:1] | passed | 0.00011 seconds |
|
|
117
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:3:1:1] | passed | 0.00004 seconds |
|
|
118
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:3:2:1] | passed | 0.00004 seconds |
|
|
119
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:3:3:1] | passed | 0.00004 seconds |
|
|
120
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:4:1] | passed | 0.00004 seconds |
|
|
121
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:5:1] | passed | 0.00003 seconds |
|
|
122
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:5:2:1] | passed | 0.00004 seconds |
|
|
123
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:6:1] | passed | 0.00009 seconds |
|
|
124
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:7:1] | passed | 0.00004 seconds |
|
|
125
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:7:2:1] | passed | 0.00004 seconds |
|
|
126
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:8:1] | passed | 0.00003 seconds |
|
|
127
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:8:2:1] | passed | 0.00004 seconds |
|
|
128
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:9:1:1] | passed | 0.00006 seconds |
|
|
129
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:9:2:1] | passed | 0.00004 seconds |
|
|
130
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:9:3:1] | passed | 0.00004 seconds |
|
|
131
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:10:1:1] | passed | 0.00004 seconds |
|
|
132
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:10:2:1] | passed | 0.00004 seconds |
|
|
133
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:11:1:1] | passed | 0.00004 seconds |
|
|
134
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:11:2:1] | passed | 0.00004 seconds |
|
|
135
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:12:1:1] | passed | 0.00004 seconds |
|
|
136
|
-
./spec/castkit/ext/attribute/options_spec.rb[1:12:2:1] | passed | 0.00004 seconds |
|
|
137
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
|
|
138
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:2:1:1] | passed | 0.00017 seconds |
|
|
139
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:2:2:1] | passed | 0.00014 seconds |
|
|
140
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:3:1] | passed | 0.00007 seconds |
|
|
141
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:4:1:1] | passed | 0.00008 seconds |
|
|
142
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:4:2:1] | passed | 0.00018 seconds |
|
|
143
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:5:1:1] | passed | 0.00008 seconds |
|
|
144
|
-
./spec/castkit/ext/attribute/validation_spec.rb[1:1:5:2:1] | passed | 0.00011 seconds |
|
|
145
|
-
./spec/castkit/ext/data_object/deserialization_spec.rb[1:1:1] | passed | 0.00015 seconds |
|
|
146
|
-
./spec/castkit/ext/data_object/deserialization_spec.rb[1:2:1] | passed | 0.00006 seconds |
|
|
147
|
-
./spec/castkit/ext/data_object/deserialization_spec.rb[1:2:2] | passed | 0.00005 seconds |
|
|
148
|
-
./spec/castkit/ext/data_object/deserialization_spec.rb[1:3:1] | passed | 0.00014 seconds |
|
|
149
|
-
./spec/castkit/ext/data_object/deserialization_spec.rb[1:4:1] | passed | 0.00006 seconds |
|
|
150
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:1:1] | passed | 0.00003 seconds |
|
|
151
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:1:2] | passed | 0.00003 seconds |
|
|
152
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:2:1] | passed | 0.00003 seconds |
|
|
153
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:2:2] | passed | 0.00003 seconds |
|
|
154
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:3:1] | passed | 0.00004 seconds |
|
|
155
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:4:1] | passed | 0.00004 seconds |
|
|
156
|
-
./spec/castkit/ext/data_object/serialization_spec.rb[1:4:2] | passed | 0.00003 seconds |
|
|
157
|
-
./spec/castkit/validators/numeric_validator_spec.rb[1:1:1:1] | passed | 0.00004 seconds |
|
|
158
|
-
./spec/castkit/validators/numeric_validator_spec.rb[1:1:2:1] | passed | 0.00004 seconds |
|
|
159
|
-
./spec/castkit/validators/numeric_validator_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
|
|
160
|
-
./spec/castkit/validators/numeric_validator_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
|
|
161
|
-
./spec/castkit/validators/string_validator_spec.rb[1:1:1:1:1] | passed | 0.00003 seconds |
|
|
162
|
-
./spec/castkit/validators/string_validator_spec.rb[1:1:2:1] | passed | 0.00004 seconds |
|
|
163
|
-
./spec/castkit/validators/string_validator_spec.rb[1:1:2:2] | passed | 0.00027 seconds |
|
|
164
|
-
./spec/castkit/validators/string_validator_spec.rb[1:1:3:1] | passed | 0.00007 seconds |
|
|
165
|
-
./spec/castkit/validators/string_validator_spec.rb[1:1:3:2] | passed | 0.00004 seconds |
|
|
166
|
-
./spec/castkit/validators/string_validator_spec.rb[1:1:4:1] | passed | 0.00006 seconds |
|
|
167
|
-
./spec/castkit/validators/validator_spec.rb[1:1:1] | passed | 0.00004 seconds |
|
|
168
|
-
./spec/castkit/validators/validator_spec.rb[1:2:1] | passed | 0.00004 seconds |
|
|
169
|
-
./spec/castkit_spec.rb[1:1] | passed | 0.00003 seconds |
|
|
170
|
-
./spec/castkit_spec.rb[1:2:1:1] | passed | 0.00015 seconds |
|
|
171
|
-
./spec/castkit_spec.rb[1:2:1:2] | passed | 0.00008 seconds |
|
|
172
|
-
./spec/castkit_spec.rb[1:2:1:3] | passed | 0.00012 seconds |
|
|
173
|
-
./spec/castkit_spec.rb[1:2:1:4] | passed | 0.00017 seconds |
|
|
174
|
-
./spec/castkit_spec.rb[1:2:2:1] | passed | 0.00013 seconds |
|
|
175
|
-
./spec/castkit_spec.rb[1:2:2:2] | passed | 0.00009 seconds |
|
|
176
|
-
./spec/castkit_spec.rb[1:2:2:3] | passed | 0.00007 seconds |
|
|
177
|
-
./spec/castkit_spec.rb[1:2:3:1] | passed | 0.0001 seconds |
|
|
178
|
-
./spec/castkit_spec.rb[1:2:3:2] | passed | 0.00007 seconds |
|
|
179
|
-
./spec/castkit_spec.rb[1:2:3:3] | passed | 0.00005 seconds |
|
|
180
|
-
./spec/castkit_spec.rb[1:2:4:1] | passed | 0.00372 seconds |
|
|
181
|
-
./spec/castkit_spec.rb[1:3:1] | passed | 0.00324 seconds |
|
|
182
|
-
./spec/castkit_spec.rb[1:3:2] | passed | 0.00333 seconds |
|
|
183
|
-
./spec/castkit_spec.rb[1:3:3] | passed | 0.00022 seconds |
|
|
184
|
-
./spec/castkit_spec.rb[1:3:4] | passed | 0.00022 seconds |
|
|
185
|
-
./spec/castkit_spec.rb[1:3:5] | passed | 0.00013 seconds |
|
|
186
|
-
./spec/castkit_spec.rb[1:3:6] | passed | 0.00017 seconds |
|
|
187
|
-
./spec/castkit_spec.rb[1:3:7] | passed | 0.00023 seconds |
|
|
188
|
-
./spec/castkit_spec.rb[1:3:8] | passed | 0.0002 seconds |
|
|
189
|
-
./spec/configuration_spec.rb[1:1:1] | passed | 0.00008 seconds |
|
|
190
|
-
./spec/configuration_spec.rb[1:2:1] | passed | 0.00005 seconds |
|
|
191
|
-
./spec/configuration_spec.rb[1:3:1] | passed | 0.00005 seconds |
|
|
192
|
-
./spec/configuration_spec.rb[1:3:2] | passed | 0.00004 seconds |
|
|
193
|
-
./spec/configuration_spec.rb[1:3:3] | passed | 0.00004 seconds |
|
|
194
|
-
./spec/configuration_spec.rb[1:3:4] | passed | 0.00006 seconds |
|
|
195
|
-
./spec/configuration_spec.rb[1:4:1] | passed | 0.00006 seconds |
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../castkit"
|
|
4
|
-
|
|
5
|
-
module Castkit
|
|
6
|
-
module Core
|
|
7
|
-
# Provides methods to register dynamically generated contracts and data objects
|
|
8
|
-
# into the appropriate Castkit namespaces (`Castkit::Contracts`, `Castkit::DataObjects`).
|
|
9
|
-
#
|
|
10
|
-
# This is useful when working with ephemeral classes (e.g., from `Contract.build` or
|
|
11
|
-
# `.to_dataobject`) that should be persisted and referenced as constants.
|
|
12
|
-
#
|
|
13
|
-
# @example Registering a contract class
|
|
14
|
-
# contract = Castkit::Contract.build(:user) { string :id }
|
|
15
|
-
# contract.extend(Castkit::Core::Registerable)
|
|
16
|
-
# contract.register! # => Castkit::Contracts::User
|
|
17
|
-
#
|
|
18
|
-
# @example Registering a DTO
|
|
19
|
-
# dto = contract.to_dataobject
|
|
20
|
-
# dto.extend(Castkit::Core::Registerable)
|
|
21
|
-
# dto.register!(as: :UserDto) # => Castkit::DataObjects::UserDto
|
|
22
|
-
module Registerable
|
|
23
|
-
CASTKIT_NAMESPACES = {
|
|
24
|
-
contracts: Castkit::Contracts,
|
|
25
|
-
dataobjects: Castkit::DataObjects
|
|
26
|
-
}.freeze
|
|
27
|
-
|
|
28
|
-
# Registers the current class in the specified Castkit namespace.
|
|
29
|
-
#
|
|
30
|
-
# @param namespace [Symbol] `:contracts` or `:dataobjects`
|
|
31
|
-
# @param as [String, Symbol, nil] Optional constant name override (PascalCase).
|
|
32
|
-
# If not provided, falls back to the class's name (via `Inflector.pascalize(self.name)`).
|
|
33
|
-
#
|
|
34
|
-
# @raise [Castkit::Error] if class is anonymous or name already exists in the namespace
|
|
35
|
-
# @return [Class] the registered class
|
|
36
|
-
def register!(namespace:, as: nil)
|
|
37
|
-
name = Castkit::Inflector.pascalize(as || self.name)
|
|
38
|
-
raise Castkit::Error, "Unable to register anonymous classes, use as: ClassName" if name.nil?
|
|
39
|
-
|
|
40
|
-
ns = Castkit.const_get(namespace.to_s.capitalize, false)
|
|
41
|
-
raise Castkit::Error, "#{name} is already registered in #{ns}" if defined_in_namespace?(ns, name)
|
|
42
|
-
|
|
43
|
-
ns.const_set(name, self)
|
|
44
|
-
self
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
# Checks whether a constant is already defined in the given namespace.
|
|
50
|
-
#
|
|
51
|
-
# @param namespace [Module] target module (e.g., `Castkit::Contracts`)
|
|
52
|
-
# @param name [String, Symbol]
|
|
53
|
-
# @return [Boolean]
|
|
54
|
-
def defined_in_namespace?(namespace, name)
|
|
55
|
-
namespace.const_defined?(name.to_s.to_sym, false)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|