types 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (10) hide show
  1. data/.document +5 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +18 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +52 -0
  6. data/Rakefile +37 -0
  7. data/VERSION +1 -0
  8. data/lib/types.rb +92 -0
  9. data/types.gemspec +54 -0
  10. metadata +118 -0
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "multitype-introspection", ">= 0.1.0"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ end
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ multitype-introspection (0.1.0)
10
+ rake (0.8.7)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.5.2)
18
+ multitype-introspection (>= 0.1.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Martin Kozák
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.
@@ -0,0 +1,52 @@
1
+ Ruby Types
2
+ ==========
3
+
4
+ **Ruby Types** introduces *group of classes* as eqivalent to some data
5
+ types in other languages such as `boolean` and allows introspection
6
+ according to type of class too. In fact, partially replaces multiple
7
+ inheritance because introduces unlimited formal genericity for every
8
+ class.
9
+
10
+ For example define:
11
+
12
+ class Boolean < Type
13
+ def type_classes
14
+ [TrueClass, FalseClass]
15
+ end
16
+ end
17
+
18
+ Then you can call:
19
+
20
+ foo = 5
21
+ bar = true
22
+
23
+ foo.type_of? Boolean # returns false
24
+ bar.type_of? Boolean # returns true
25
+
26
+ Binding back to classic behaviour works:
27
+
28
+ foo.type_of? Numeric # returns true
29
+
30
+ By overriding `#type_types` method of the `Type` class you can achieve
31
+ also types inheritance by the same way as mentioned above.
32
+
33
+
34
+ Contributing
35
+ ------------
36
+
37
+ 1. Fork it.
38
+ 2. Create a branch (`git checkout -b 20101220-my-change`).
39
+ 3. Commit your changes (`git commit -am "Added something"`).
40
+ 4. Push to the branch (`git push origin 20101220-my-change`).
41
+ 5. Create an [Issue][1] with a link to your branch.
42
+ 6. Enjoy a refreshing Diet Coke and wait.
43
+
44
+
45
+ Copyright
46
+ ---------
47
+
48
+ Copyright &copy; 2011 [Martin Kozák][2]. See `LICENSE.txt` for
49
+ further details.
50
+
51
+ [1]: http://github.com/martinkozak/types/issues
52
+ [2]: http://www.martinkozak.net/
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "types"
17
+ gem.homepage = "http://github.com/martinkozak/types"
18
+ gem.license = "MIT"
19
+ gem.summary = 'Introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.'
20
+ gem.email = "martinkozak@martinkozak.net"
21
+ gem.authors = ["Martin Kozák"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/rdoctask'
30
+ Rake::RDocTask.new do |rdoc|
31
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
32
+
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = "types #{version}"
35
+ rdoc.rdoc_files.include('README*')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ require "multitype-introspection"
5
+
6
+ module Types
7
+ class Type
8
+
9
+ ##
10
+ # Returns classes which are part of this type.
11
+ #
12
+
13
+ def type_classes
14
+ raise Exception::new("Class is abstract.")
15
+ end
16
+
17
+ ##
18
+ # Returns types which are part of this type.
19
+ #
20
+
21
+ def type_types
22
+ [ ]
23
+ end
24
+
25
+ ##
26
+ # Matches object is of this type.
27
+ #
28
+
29
+ def match_type?(object)
30
+ result = object.kind_of_any? self.type_classes
31
+ if not result
32
+ result = object.type_of_any? self.type_types
33
+ end
34
+
35
+ return result
36
+ end
37
+
38
+ end
39
+
40
+ class Boolean < Type
41
+
42
+ ##
43
+ # Returns classes which are part of this type.
44
+ # In case of boolean <tt>TrueClass</tt> and <tt>FalseClass</tt>.
45
+ #
46
+
47
+ def type_classes
48
+ [TrueClass, FalseClass]
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+ class Object
55
+
56
+ ##
57
+ # Indicates object is type of some class.
58
+ # If class isn't Type, matches against kind_of?.
59
+ #
60
+
61
+ def type_of?(cls)
62
+ cls_new = cls::new
63
+ if cls_new.kind_of? Types::Type
64
+ cls_new.match_type? self
65
+ else
66
+ self.kind_of? cls
67
+ end
68
+ end
69
+
70
+
71
+ ##
72
+ # Indicates object is type of some class in the list.
73
+ # If class isn't Type, matches against kind_of?.
74
+ #
75
+
76
+ def type_of_any?(classes)
77
+ if not classes.kind_of? Array
78
+ raise Exception::new("Array expected.")
79
+ end
80
+
81
+ classes.each do |cls|
82
+ if self.type_of? cls
83
+ return true
84
+ end
85
+ end
86
+
87
+ return false
88
+ end
89
+ end
90
+
91
+ class Boolean < Types::Boolean
92
+ end
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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{types}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Martin Kozák"]
12
+ s.date = %q{2011-01-12}
13
+ s.email = %q{martinkozak@martinkozak.net}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/types.rb",
27
+ "types.gemspec"
28
+ ]
29
+ s.homepage = %q{http://github.com/martinkozak/types}
30
+ s.licenses = ["MIT"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{Introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<multitype-introspection>, [">= 0.1.0"])
41
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
42
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
43
+ else
44
+ s.add_dependency(%q<multitype-introspection>, [">= 0.1.0"])
45
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<multitype-introspection>, [">= 0.1.0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
52
+ end
53
+ end
54
+
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: types
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - "Martin Koz\xC3\xA1k"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-12 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: multitype-introspection
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 0
31
+ version: 0.1.0
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 2
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ description:
66
+ email: martinkozak@martinkozak.net
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE.txt
73
+ - README.md
74
+ files:
75
+ - .document
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - VERSION
82
+ - lib/types.rb
83
+ - types.gemspec
84
+ has_rdoc: true
85
+ homepage: http://github.com/martinkozak/types
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 2336525954248439529
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.
117
+ test_files: []
118
+