required_struct 0.1.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 +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +21 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/lib/required_struct/version.rb +5 -0
- data/lib/required_struct.rb +18 -0
- data/required_struct.gemspec +25 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2be293ffd7d345feaee877c092332567f11d275af7e5864981d05a7c12f60aff
|
4
|
+
data.tar.gz: 5ff585dcc64444ca12e76e0bde5549806e74d3f40a842a0084e34d04f465027d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ceeccd529a45dcce6beebe270319fd2381693d5010619da49bf66f408621694fd1a42ee7aa58f39a2ac8144e7d0a0aa454736633da1ac181dd8f7f3c43fc596
|
7
|
+
data.tar.gz: 413c2799608c1cf7e75940c5d07ca26f86b32cad8e4f562f2a114702719b37aea6e9e4ce5bde8050a44889d57475c16f01e82462453692d9da395d5c32ee8c18
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
required_struct (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.16.3)
|
10
|
+
rake (13.0.6)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
x86_64-linux
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
minitest (~> 5.0)
|
17
|
+
rake (~> 13.0)
|
18
|
+
required_struct!
|
19
|
+
|
20
|
+
BUNDLED WITH
|
21
|
+
2.3.15
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# RequiredStruct
|
2
|
+
|
3
|
+
RequiredStruct Creates a Struct that enforces the specified keyword at initialization
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add strict_struct
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install strict_struct
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'strict_struct'
|
19
|
+
|
20
|
+
dog = RequiredStruct.new("Dog", :name, :age)
|
21
|
+
fred = dog.new(name: "fred", age: 5)
|
22
|
+
|
23
|
+
choco = dog.new(name: "choco")
|
24
|
+
#=> Missing Keywords: age (RequiredStruct::StructArgumentError)
|
25
|
+
```
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "required_struct/version"
|
4
|
+
|
5
|
+
module RequiredStruct
|
6
|
+
class StructArgumentError < StandardError; end
|
7
|
+
def self.new(*args)
|
8
|
+
Struct.new(*args, keyword_init: true) do
|
9
|
+
def initialize(**args)
|
10
|
+
a = self.members.difference(args.keys)
|
11
|
+
raise StructArgumentError.new("Missing Keywords: #{a.join(', ')}") unless a.empty?
|
12
|
+
b = args.keys.difference(self.members)
|
13
|
+
raise StructArgumentError.new("Unknown Keywords: #{b.join(', ')}") unless b.empty?
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/required_struct/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "required_struct"
|
7
|
+
spec.version = RequiredStruct::VERSION
|
8
|
+
spec.authors = ["Yuu Yamanoi"]
|
9
|
+
|
10
|
+
spec.summary = "RequiredStruct Creates a Struct that enforces the specified keyword at initialization"
|
11
|
+
spec.description = "RequiredStruct Creates a Struct that enforces the specified keyword at initialization"
|
12
|
+
spec.homepage = "https://github.com/yyamanoi1222/required_struct"
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(__dir__) do
|
20
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: required_struct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuu Yamanoi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: RequiredStruct Creates a Struct that enforces the specified keyword at
|
14
|
+
initialization
|
15
|
+
email:
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/required_struct.rb
|
25
|
+
- lib/required_struct/version.rb
|
26
|
+
- required_struct.gemspec
|
27
|
+
homepage: https://github.com/yyamanoi1222/required_struct
|
28
|
+
licenses: []
|
29
|
+
metadata:
|
30
|
+
homepage_uri: https://github.com/yyamanoi1222/required_struct
|
31
|
+
source_code_uri: https://github.com/yyamanoi1222/required_struct
|
32
|
+
changelog_uri: https://github.com/yyamanoi1222/required_struct
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.6.0
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.3.8
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: RequiredStruct Creates a Struct that enforces the specified keyword at initialization
|
52
|
+
test_files: []
|