strict 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +14 -2
  3. data/Gemfile.lock +18 -1
  4. data/README.md +100 -6
  5. data/lib/strict/accessor/attributes.rb +15 -0
  6. data/lib/strict/accessor/module.rb +45 -0
  7. data/lib/strict/assignment_error.rb +25 -0
  8. data/lib/strict/attribute.rb +71 -0
  9. data/lib/strict/attributes/configuration.rb +46 -0
  10. data/lib/strict/attributes/configured.rb +13 -0
  11. data/lib/strict/attributes/dsl.rb +42 -0
  12. data/lib/strict/attributes/instance.rb +68 -0
  13. data/lib/strict/dsl/validatable.rb +28 -0
  14. data/lib/strict/initialization_error.rb +57 -0
  15. data/lib/strict/method.rb +52 -0
  16. data/lib/strict/method_call_error.rb +72 -0
  17. data/lib/strict/method_definition_error.rb +46 -0
  18. data/lib/strict/method_return_error.rb +25 -0
  19. data/lib/strict/methods/configuration.rb +14 -0
  20. data/lib/strict/methods/dsl.rb +55 -0
  21. data/lib/strict/methods/module.rb +26 -0
  22. data/lib/strict/methods/verifiable_method.rb +158 -0
  23. data/lib/strict/object.rb +9 -0
  24. data/lib/strict/parameter.rb +63 -0
  25. data/lib/strict/reader/attributes.rb +15 -0
  26. data/lib/strict/reader/module.rb +27 -0
  27. data/lib/strict/return.rb +28 -0
  28. data/lib/strict/validators/all_of.rb +24 -0
  29. data/lib/strict/validators/any_of.rb +24 -0
  30. data/lib/strict/validators/anything.rb +20 -0
  31. data/lib/strict/validators/array_of.rb +24 -0
  32. data/lib/strict/validators/boolean.rb +20 -0
  33. data/lib/strict/validators/hash_of.rb +25 -0
  34. data/lib/strict/validators/range_of.rb +24 -0
  35. data/lib/strict/value.rb +22 -0
  36. data/lib/strict/version.rb +1 -1
  37. data/lib/strict.rb +1 -0
  38. data/strict.gemspec +41 -0
  39. metadata +90 -2
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strict
4
+ module Validators
5
+ class RangeOf
6
+ attr_reader :element_validator
7
+
8
+ def initialize(element_validator)
9
+ @element_validator = element_validator
10
+ end
11
+
12
+ def ===(value)
13
+ Range === value && [value.begin, value.end].compact.all? do |v|
14
+ element_validator === v
15
+ end
16
+ end
17
+
18
+ def inspect
19
+ "RangeOf(#{element_validator.inspect})"
20
+ end
21
+ alias to_s inspect
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strict
4
+ module Value
5
+ def self.included(mod)
6
+ mod.extend(Reader::Attributes)
7
+ end
8
+
9
+ def with(**attributes)
10
+ self.class.new(**to_h.merge(attributes))
11
+ end
12
+
13
+ def eql?(other)
14
+ self.class.equal?(other.class) && to_h.eql?(other.to_h)
15
+ end
16
+ alias == eql?
17
+
18
+ def hash
19
+ [self.class, to_h].hash
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strict
4
- VERSION = "0.0.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/strict.rb CHANGED
@@ -5,4 +5,5 @@ loader = Zeitwerk::Loader.for_gem
5
5
  loader.setup
6
6
 
7
7
  module Strict
8
+ ISSUE_TRACKER = "https://github.com/kylekthompson/strict/issues"
8
9
  end
data/strict.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/strict/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "strict"
7
+ spec.version = Strict::VERSION
8
+ spec.authors = ["Kyle Thompson"]
9
+ spec.email = ["me@kkt.dev"]
10
+
11
+ spec.summary = "Strictly define a contract for your objects and methods"
12
+ spec.homepage = "https://github.com/kylekthompson/strict"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.1.2"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
21
+ spec.metadata["rubygems_mfa_required"] = "true"
22
+
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "zeitwerk", "~> 2.6"
33
+ spec.add_development_dependency "debug", ">= 1.0.0"
34
+ spec.add_development_dependency "gem-release", "~> 2.2"
35
+ spec.add_development_dependency "minitest", "~> 5.0"
36
+ spec.add_development_dependency "minitest-spec-context", "~> 0.0.4"
37
+ spec.add_development_dependency "rake", "~> 13.0"
38
+ spec.add_development_dependency "rubocop", "~> 1.21"
39
+ spec.add_development_dependency "rubocop-minitest", "~> 0.22"
40
+ spec.add_development_dependency "rubocop-rake", "~> 0.6"
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Thompson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-01 00:00:00.000000000 Z
11
+ date: 2022-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: debug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: gem-release
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-spec-context
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.4
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,34 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: '1.21'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.22'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.22'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.6'
83
139
  description:
84
140
  email:
85
141
  - me@kkt.dev
@@ -96,9 +152,41 @@ files:
96
152
  - README.md
97
153
  - Rakefile
98
154
  - lib/strict.rb
155
+ - lib/strict/accessor/attributes.rb
156
+ - lib/strict/accessor/module.rb
157
+ - lib/strict/assignment_error.rb
158
+ - lib/strict/attribute.rb
159
+ - lib/strict/attributes/configuration.rb
160
+ - lib/strict/attributes/configured.rb
161
+ - lib/strict/attributes/dsl.rb
162
+ - lib/strict/attributes/instance.rb
163
+ - lib/strict/dsl/validatable.rb
99
164
  - lib/strict/error.rb
165
+ - lib/strict/initialization_error.rb
166
+ - lib/strict/method.rb
167
+ - lib/strict/method_call_error.rb
168
+ - lib/strict/method_definition_error.rb
169
+ - lib/strict/method_return_error.rb
170
+ - lib/strict/methods/configuration.rb
171
+ - lib/strict/methods/dsl.rb
172
+ - lib/strict/methods/module.rb
173
+ - lib/strict/methods/verifiable_method.rb
174
+ - lib/strict/object.rb
175
+ - lib/strict/parameter.rb
176
+ - lib/strict/reader/attributes.rb
177
+ - lib/strict/reader/module.rb
178
+ - lib/strict/return.rb
179
+ - lib/strict/validators/all_of.rb
180
+ - lib/strict/validators/any_of.rb
181
+ - lib/strict/validators/anything.rb
182
+ - lib/strict/validators/array_of.rb
183
+ - lib/strict/validators/boolean.rb
184
+ - lib/strict/validators/hash_of.rb
185
+ - lib/strict/validators/range_of.rb
186
+ - lib/strict/value.rb
100
187
  - lib/strict/version.rb
101
188
  - sig/strict.rbs
189
+ - strict.gemspec
102
190
  homepage: https://github.com/kylekthompson/strict
103
191
  licenses:
104
192
  - MIT