tstruct 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tstruct.rb +18 -0
- data/lib/tstruct/version.rb +3 -0
- data/tstruct.gemspec +26 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd8664da4b3a76614b8a39d3d3c5c3c78a42a7e3e694c00469f1af90b10a0954
|
4
|
+
data.tar.gz: 215ee9c4e03b0608af7ecec82b9907efba5ca6fc8fe5fa8e2fd156e0a77c89c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ca6bc5433a912d200b2e89247a3586824da6863957661a86f98c16b41553c06fa062e467186f3f9ca61579d166be56929d3991a5aae2057a49232ee085ddef3
|
7
|
+
data.tar.gz: 6a0f054f86dd17772b800c759aa66fb23bea013e300f1496229dca6e1ba6b6224876a09aed08e0c1a6084e5bfde428624a68d5bd78861229e05bc54c131b6c18
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/osyo-manga/gem-tstruct.svg?branch=master)](https://travis-ci.org/osyo-manga/gem-tstruct)
|
2
|
+
|
3
|
+
# TStruct
|
4
|
+
|
5
|
+
`TStruct` is type checked `Struct`
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'tstruct'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install tstruct
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "tstruct"
|
28
|
+
|
29
|
+
# propaty names with Type
|
30
|
+
# Type must has `#===`
|
31
|
+
User = TStruct.new(id: Integer, name: String, age: Integer)
|
32
|
+
|
33
|
+
homu = User.new(1, "homu", 14)
|
34
|
+
|
35
|
+
# OK
|
36
|
+
homu.name = "homuhomu"
|
37
|
+
|
38
|
+
# error: TypeError
|
39
|
+
homu.age = "14"
|
40
|
+
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require "tstruct"
|
46
|
+
|
47
|
+
# Use Regexp and Range
|
48
|
+
User = TStruct.new(id: Integer, name: /^h/, age: (1..20))
|
49
|
+
|
50
|
+
homu = User.new(1, "homu", 14)
|
51
|
+
|
52
|
+
# error: TypeError
|
53
|
+
homu.name = "mami"
|
54
|
+
|
55
|
+
# OK
|
56
|
+
homu.age = 15
|
57
|
+
|
58
|
+
# error: TypeError
|
59
|
+
homu.age = 21
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/osyo-manga/gem-tstruct.
|
72
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tstruct"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/tstruct.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "tstruct/version"
|
2
|
+
|
3
|
+
def TStruct(sig)
|
4
|
+
Module.new {
|
5
|
+
sig.each { |name, type|
|
6
|
+
define_method(:"#{name}=") { |value|
|
7
|
+
raise TypeError unless type === value
|
8
|
+
method(:"#{name}=").super_method.call value
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
module TStruct
|
15
|
+
def self.new(sig)
|
16
|
+
Struct.new(*sig.keys).prepend TStruct(sig)
|
17
|
+
end
|
18
|
+
end
|
data/tstruct.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/tstruct/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "tstruct"
|
5
|
+
spec.version = TStruct::VERSION
|
6
|
+
spec.authors = ["manga_osyo"]
|
7
|
+
spec.email = ["manga.osyo@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{TStruct is type checked Struct}
|
10
|
+
spec.description = %q{TStruct is type checked Struct}
|
11
|
+
spec.homepage = "https://github.com/osyo-manga/gem-tstruct"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/osyo-manga/gem-tstruct"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/osyo-manga/gem-tstruct"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tstruct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- manga_osyo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: TStruct is type checked Struct
|
14
|
+
email:
|
15
|
+
- manga.osyo@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- Gemfile
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/tstruct.rb
|
29
|
+
- lib/tstruct/version.rb
|
30
|
+
- tstruct.gemspec
|
31
|
+
homepage: https://github.com/osyo-manga/gem-tstruct
|
32
|
+
licenses: []
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/osyo-manga/gem-tstruct
|
35
|
+
source_code_uri: https://github.com/osyo-manga/gem-tstruct
|
36
|
+
changelog_uri: https://github.com/osyo-manga/gem-tstruct
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: TStruct is type checked Struct
|
56
|
+
test_files: []
|