tstruct 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tstruct.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -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
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -0,0 +1,3 @@
1
+ module TStruct
2
+ VERSION = "0.1.0"
3
+ end
@@ -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: []