tsalzer-typesafe 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/features/step_definitions/typesafe_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/features/typesafe.feature +9 -0
- data/lib/typesafe.rb +51 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/typesafe_spec.rb +35 -0
- data/typesafe.gemspec +61 -0
- metadata +87 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Till Salzer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= typesafe
|
2
|
+
|
3
|
+
Typesafe is a tiny extension to core Ruby to simplify checks for
|
4
|
+
kind_of?.
|
5
|
+
|
6
|
+
== Note on Patches/Pull Requests
|
7
|
+
|
8
|
+
* Fork the project.
|
9
|
+
* Make your feature addition or bug fix.
|
10
|
+
* Add tests for it. This is important so I don't break it in a
|
11
|
+
future version unintentionally.
|
12
|
+
* Commit, do not mess with rakefile, version, or history.
|
13
|
+
(if you want to have your own version, that is fine but
|
14
|
+
bump version in a commit by itself I can ignore when I pull)
|
15
|
+
* Send me a pull request. Bonus points for topic branches.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2009 Till Salzer. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "typesafe"
|
8
|
+
gem.summary = %Q{provides Object#must_be_kind_of for typesafe development}
|
9
|
+
gem.description = %Q{Simplifies typesafe development by providing the additional
|
10
|
+
methods Object#must_by_kind_of ad Object#must_be_a.}
|
11
|
+
gem.email = "till.salzer@googlemail.com"
|
12
|
+
gem.homepage = "http://github.com/tsalzer/typesafe"
|
13
|
+
gem.authors = ["Till Salzer"]
|
14
|
+
gem.add_development_dependency "rspec"
|
15
|
+
gem.add_development_dependency "cucumber"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'cucumber/rake/task'
|
38
|
+
Cucumber::Rake::Task.new(:features)
|
39
|
+
|
40
|
+
task :features => :check_dependencies
|
41
|
+
rescue LoadError
|
42
|
+
task :features do
|
43
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
if File.exist?('VERSION')
|
52
|
+
version = File.read('VERSION')
|
53
|
+
else
|
54
|
+
version = ""
|
55
|
+
end
|
56
|
+
|
57
|
+
rdoc.rdoc_dir = 'rdoc'
|
58
|
+
rdoc.title = "typesafe #{version}"
|
59
|
+
rdoc.rdoc_files.include('README*')
|
60
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
File without changes
|
data/lib/typesafe.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# additional features for all objects
|
2
|
+
|
3
|
+
class TypeCheckError < RuntimeError ; end
|
4
|
+
|
5
|
+
module TypeSafe
|
6
|
+
module ObjectTypeChecks
|
7
|
+
# this object must be kind of a given class.
|
8
|
+
def must_be_kind_of(clss)
|
9
|
+
if clss.kind_of?(Module)
|
10
|
+
raise TypeCheckError.new("#{self} must include module #{clss}") unless self.kind_of?(clss)
|
11
|
+
elsif clss.kind_of?(Class)
|
12
|
+
raise TypeCheckError.new("#{self} must be of type #{clss}") unless self.kind_of?(clss)
|
13
|
+
else
|
14
|
+
raise "class to check #{self} for must be a Class or Module, but is #{clss}"
|
15
|
+
end
|
16
|
+
true
|
17
|
+
end
|
18
|
+
alias must_be_a must_be_kind_of
|
19
|
+
|
20
|
+
# this object must be kind of a given class.
|
21
|
+
def must_be_nil_or_kind_of(clss)
|
22
|
+
self.kind_of?(NilClass) ? true : must_be_kind_of(clss)
|
23
|
+
end
|
24
|
+
|
25
|
+
end#ObjectTypeChecks
|
26
|
+
|
27
|
+
module ClassTypeChecks
|
28
|
+
# this object must be kind of a given class.
|
29
|
+
def class_must_be_kind_of(clss)
|
30
|
+
if clss.kind_of?(Module)
|
31
|
+
raise TypeCheckError.new("#{self} must include module #{clss}") unless self.kind_of?(clss)
|
32
|
+
elsif clss.kind_of?(Class)
|
33
|
+
raise TypeCheckError.new("#{self} must be of type #{clss}") unless self.kind_of?(clss)
|
34
|
+
else
|
35
|
+
raise "class to check #{self} for must be a Class or Module, but is #{clss}"
|
36
|
+
end
|
37
|
+
true
|
38
|
+
end
|
39
|
+
alias class_must_be_a class_must_be_kind_of
|
40
|
+
|
41
|
+
# this object must be kind of a given class.
|
42
|
+
def must_be_nil_or_kind_of(clss)
|
43
|
+
self.kind_of?(NilClass) ? true : must_be_kind_of(clss)
|
44
|
+
end
|
45
|
+
|
46
|
+
end#ClassTypeChecks
|
47
|
+
|
48
|
+
Object.send :include, ObjectTypeChecks
|
49
|
+
Class.send :include, ClassTypeChecks
|
50
|
+
|
51
|
+
end#TypeSafe
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
{:must_be_kind_of => false, :must_be_a => false, :must_be_nil_or_kind_of => true}.each do |method, nil_allowed|
|
4
|
+
describe TypeSafe, ".#{method}" do
|
5
|
+
it "should be included in Object class" do
|
6
|
+
Object.new.should respond_to(method)
|
7
|
+
end
|
8
|
+
it "should recognize a simple type" do
|
9
|
+
lambda{1.send method, Fixnum}.should_not raise_error(TypeCheckError)
|
10
|
+
end
|
11
|
+
it "should recognize parent classes" do
|
12
|
+
lambda{self.send method, Object}.should_not raise_error(TypeCheckError)
|
13
|
+
end
|
14
|
+
it "should raise a TypeCheckError for mismatching types" do
|
15
|
+
lambda{"1".send method, Fixnum}.should raise_error(TypeCheckError)
|
16
|
+
end
|
17
|
+
it "should raise a RuntimeError if the given match is not a Class" do
|
18
|
+
lambda{"1".send method, "Fixnum"}.should raise_error(RuntimeError)
|
19
|
+
lambda{"1".send method, "Fixnum"}.should_not raise_error(TypeCheckError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should #{nil_allowed ? 'not ' : ''}raise a TypeCheckError for mismatching types on nil" do
|
23
|
+
lambda{nil.send method, Fixnum}.send nil_allowed ? :should_not : :should, raise_error(TypeCheckError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should recognize included modules" do
|
27
|
+
module TestModule ; end
|
28
|
+
class TestClass
|
29
|
+
include TestModule
|
30
|
+
end
|
31
|
+
o = TestClass.new
|
32
|
+
lambda{o.send method, TestModule}.should_not raise_error(TypeCheckError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/typesafe.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{typesafe}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Till Salzer"]
|
12
|
+
s.date = %q{2009-08-24}
|
13
|
+
s.description = %q{Simplifies typesafe development by providing the additional
|
14
|
+
methods Object#must_by_kind_of ad Object#must_be_a.}
|
15
|
+
s.email = %q{till.salzer@googlemail.com}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"features/step_definitions/typesafe_steps.rb",
|
28
|
+
"features/support/env.rb",
|
29
|
+
"features/typesafe.feature",
|
30
|
+
"lib/typesafe.rb",
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"spec/typesafe_spec.rb",
|
33
|
+
"typesafe.gemspec"
|
34
|
+
]
|
35
|
+
s.has_rdoc = true
|
36
|
+
s.homepage = %q{http://github.com/tsalzer/typesafe}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.2}
|
40
|
+
s.summary = %q{provides Object#must_be_kind_of for typesafe development}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"spec/typesafe_spec.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
55
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tsalzer-typesafe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Till Salzer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: cucumber
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Simplifies typesafe development by providing the additional methods Object#must_by_kind_of ad Object#must_be_a.
|
36
|
+
email: till.salzer@googlemail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- features/step_definitions/typesafe_steps.rb
|
52
|
+
- features/support/env.rb
|
53
|
+
- features/typesafe.feature
|
54
|
+
- lib/typesafe.rb
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- spec/typesafe_spec.rb
|
57
|
+
- typesafe.gemspec
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/tsalzer/typesafe
|
60
|
+
licenses:
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: provides Object#must_be_kind_of for typesafe development
|
85
|
+
test_files:
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/typesafe_spec.rb
|