keso 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Darwin B Blomqvist
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,23 @@
1
+ = keso
2
+
3
+ A relation implementation based in inspiration from "The Third Manifesto".
4
+
5
+ The goal of this to make it easier to organize data.
6
+
7
+ This is a evolutionary project that will change shape with changing understudying of the problem.
8
+
9
+ If you find Keso interesting checkout this other http://github.com/dkubb/veritas.
10
+
11
+ == Note on Patches/Pull Requests
12
+
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Add tests for it. This is important so I don't break it in a
16
+ future version unintentionally.
17
+ * Commit, do not mess with rakefile, version, or history.
18
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2010 Darwin B Blomqvist. See LICENSE for details.
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "keso"
8
+ gem.summary = %Q{Cottage cheees with lots of relational theory}
9
+ gem.description = %Q{Cottage cheees with lots of relational theory. Or mabye not so much theory =(}
10
+ gem.email = "darwin@markkonsulter.se"
11
+ gem.homepage = "http://github.com/bjornblomqvist/keso"
12
+ gem.authors = ["Darwin"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ # require 'spec/rake/spectask'
21
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ # spec.libs << 'lib' << 'spec'
23
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ # end
25
+
26
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ # spec.libs << 'lib' << 'spec'
28
+ # spec.pattern = 'spec/**/*_spec.rb'
29
+ # spec.rcov = true
30
+ # end
31
+
32
+ # task :spec => :check_dependencies
33
+ #
34
+ # task :default => :spec
35
+ #
36
+ # require 'rake/rdoctask'
37
+ # Rake::RDocTask.new do |rdoc|
38
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+ #
40
+ # rdoc.rdoc_dir = 'rdoc'
41
+ # rdoc.title = "keso #{version}"
42
+ # rdoc.rdoc_files.include('README*')
43
+ # rdoc.rdoc_files.include('lib/**/*.rb')
44
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{keso}
8
+ s.version = "0.1.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Darwin"]
12
+ s.date = %q{2010-10-29}
13
+ s.description = %q{Cottage cheees with lots of relational theory. Or mabye not so much theory =(}
14
+ s.email = %q{darwin@markkonsulter.se}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "keso.gemspec",
27
+ "lib/keso.rb",
28
+ "lib/realvar.rb",
29
+ "lib/values/attribute.rb",
30
+ "lib/values/heading.rb",
31
+ "lib/values/immutable_hash.rb",
32
+ "lib/values/immutable_set.rb",
33
+ "lib/values/relation.rb",
34
+ "lib/values/tuple.rb",
35
+ "spec/attribute_spec.rb",
36
+ "spec/heading_spec.rb",
37
+ "spec/immutable_hash_spec.rb",
38
+ "spec/immutable_set_spec.rb",
39
+ "spec/relation_spec.rb",
40
+ "spec/spec.opts",
41
+ "spec/spec_helper.rb",
42
+ "spec/tuple_spec.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/bjornblomqvist/keso}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.7}
48
+ s.summary = %q{Cottage cheees with lots of relational theory}
49
+ s.test_files = [
50
+ "spec/attribute_spec.rb",
51
+ "spec/heading_spec.rb",
52
+ "spec/immutable_hash_spec.rb",
53
+ "spec/immutable_set_spec.rb",
54
+ "spec/relation_spec.rb",
55
+ "spec/spec_helper.rb",
56
+ "spec/tuple_spec.rb"
57
+ ]
58
+
59
+ if s.respond_to? :specification_version then
60
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
65
+ else
66
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,8 @@
1
+
2
+ require File.dirname(__FILE__)+'/values/immutable_hash'
3
+ require File.dirname(__FILE__)+'/values/immutable_set'
4
+ require File.dirname(__FILE__)+'/values/attribute'
5
+ require File.dirname(__FILE__)+'/values/heading'
6
+ require File.dirname(__FILE__)+'/values/tuple'
7
+ require File.dirname(__FILE__)+'/values/relation'
8
+
@@ -0,0 +1,12 @@
1
+
2
+
3
+ A relatinal variable
4
+
5
+ Can take a relational value
6
+ Can have constraints to the relatinal value
7
+
8
+
9
+
10
+
11
+
12
+
@@ -0,0 +1,44 @@
1
+
2
+ class Attribute
3
+ attr_reader :name,:type
4
+
5
+ def initialize name_or_hash,type = nil
6
+ name = nil
7
+ if name_or_hash.is_a? Hash
8
+ name = name_or_hash[:name]
9
+ type = name_or_hash[:type]
10
+ else
11
+ name = name_or_hash
12
+ end
13
+
14
+ unless(type.is_a?(Class) || type.is_a?(Heading))
15
+ type = type.class
16
+ end
17
+
18
+ throw "Type cant be nil, :#{name} => #{type}" if type == NilClass
19
+
20
+
21
+ @name = name.to_s
22
+ @type = type
23
+ end
24
+
25
+ def eql? other
26
+ self == other
27
+ end
28
+
29
+ def hash
30
+ name.hash + type.hash
31
+ end
32
+
33
+ def == object
34
+ if object.equal?(self)
35
+ true
36
+ elsif !self.class.equal?(object.class)
37
+ false
38
+ else
39
+ object.name == self.name && object.type == self.type
40
+ end
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,125 @@
1
+
2
+ class Heading
3
+
4
+ def initialize values = nil
5
+ @attributes = ImmutableSet.new
6
+
7
+ if values.is_a? Attribute
8
+ @attributes = @attributes.add values
9
+ elsif values.is_a? ImmutableSet
10
+ @attributes = values
11
+ elsif values.is_a? Hash
12
+ @attributes = @attributes.add(Attribute.new(values))
13
+ elsif values.is_a? Heading
14
+ values.get_attributes.each do |attribute|
15
+ @attributes = @attributes.add(attribute)
16
+ end
17
+ elsif values.nil?
18
+ # Nil is the same as a no params
19
+ else
20
+ raise 'Invalid parameter, expected a hash with name and type or a attribute'
21
+ end
22
+ end
23
+
24
+ def names
25
+ toReturn = []
26
+ @attributes.each do |attribute|
27
+ toReturn << attribute.name
28
+ end
29
+
30
+ toReturn
31
+ end
32
+
33
+ def add values
34
+ if values.is_a? Attribute
35
+ Heading.new(@attributes.add(values))
36
+ elsif values.is_a? Hash
37
+ Heading.new(@attributes.add(Attribute.new(values)))
38
+ elsif values.is_a? Heading
39
+ toReturn = Heading.new(self)
40
+ values.get_attributes.each do |attribute|
41
+ toReturn = toReturn.add(attribute)
42
+ end
43
+ toReturn
44
+ else
45
+ throw "Unknown argument #{values.class}"
46
+ end
47
+ end
48
+
49
+ def hash
50
+ @attributes.hash
51
+ end
52
+
53
+ def == object
54
+ if object.equal?(self)
55
+ true
56
+ elsif !self.class.equal?(object.class)
57
+ false
58
+ else
59
+ self.get_attributes.eql?(object.get_attributes)
60
+ end
61
+ end
62
+
63
+ def eql? other
64
+ self == other
65
+ end
66
+
67
+ def each &block
68
+ @attributes.each do |value|
69
+ block.call value
70
+ end
71
+ end
72
+
73
+ def [] attribute_name
74
+ @attributes.to_a.each do |value|
75
+ if value.name == attribute_name.to_s
76
+ return value
77
+ end
78
+ end
79
+
80
+ nil
81
+ end
82
+
83
+ def rename from,to
84
+ throw "Missing from" if self[from].nil?
85
+ throw "to already exists" unless self[to].nil?
86
+
87
+ Heading.new(@attributes).remove(from).add(:name => to, :type => self[from].type)
88
+ end
89
+
90
+ def remove attribute_or_name
91
+ if attribute_or_name.is_a? Attribute
92
+ Heading.new(@attributes.remove(attribute_or_name))
93
+ else
94
+ result = nil
95
+ @attributes.to_a.each do |value|
96
+ if value.name == attribute_or_name.to_s
97
+ result = value
98
+ end
99
+ end
100
+ if result
101
+ Heading.new(@attributes.remove(result))
102
+ else
103
+ Heading.new @attributes
104
+ end
105
+ end
106
+ end
107
+
108
+ def count
109
+ @attributes.count
110
+ end
111
+
112
+ def first
113
+ @attributes.to_a.first
114
+ end
115
+
116
+ protected
117
+
118
+ def get_attributes
119
+ @attributes
120
+ end
121
+
122
+ end
123
+
124
+
125
+
@@ -0,0 +1,112 @@
1
+
2
+ class ImmutableHash
3
+
4
+ def initialize key_or_hash = nil,value = nil
5
+
6
+ @hash = {}
7
+
8
+ if key_or_hash.is_a?(ImmutableHash) || key_or_hash.is_a?(Hash)
9
+ key_or_hash.keys.each do |key|
10
+ @hash[key] = key_or_hash[key]
11
+ end
12
+ elsif !key_or_hash.nil?
13
+ @hash[key_or_hash] = value
14
+ end
15
+ end
16
+
17
+ def [] key
18
+ @hash[key]
19
+ end
20
+
21
+ def set key_or_hash,value = nil
22
+ add key_or_hash,value
23
+ end
24
+
25
+ def keys
26
+ @hash.keys
27
+ end
28
+
29
+ def values
30
+ @hash.values
31
+ end
32
+
33
+ def count
34
+ @hash.count
35
+ end
36
+
37
+ def size
38
+ @hash.size
39
+ end
40
+
41
+ def - to_remove
42
+ delete to_remove
43
+ end
44
+
45
+ def each
46
+ @hash.each do |key,value|
47
+ yield key,value
48
+ end
49
+ end
50
+
51
+ def delete *to_remove
52
+
53
+ newHash = @hash.clone
54
+
55
+ to_remove.each do |to_remove|
56
+ if to_remove.is_a?(ImmutableHash) || to_remove.is_a?(Hash)
57
+ to_remove.keys.each do |value|
58
+ newHash.delete value if newHash[value] == to_remove[value]
59
+ end
60
+ elsif to_remove.is_a? Array
61
+ to_remove.each do |value|
62
+ newHash.delete value
63
+ end
64
+ else
65
+ newHash.delete to_remove
66
+ end
67
+ end
68
+
69
+ ImmutableHash.new newHash
70
+ end
71
+
72
+ def add key_or_hash,value = nil
73
+ if key_or_hash.is_a?(ImmutableHash) || key_or_hash.is_a?(Hash)
74
+ newHash = @hash.clone
75
+ key_or_hash.keys.each do |key|
76
+ newHash[key] = key_or_hash[key]
77
+ end
78
+ ImmutableHash.new(newHash)
79
+ else
80
+ newHash = @hash.clone
81
+ newHash[key_or_hash] = value
82
+ ImmutableHash.new newHash
83
+ end
84
+ end
85
+
86
+ def == object
87
+ eql? object
88
+ end
89
+
90
+ def eql?(object)
91
+ if object.equal?(self)
92
+ true
93
+ elsif !self.class.equal?(object.class)
94
+ false
95
+ else
96
+ self.inner_hash.eql?(object.inner_hash)
97
+ end
98
+ end
99
+
100
+ def hash
101
+ @hash.hash
102
+ end
103
+
104
+ protected
105
+
106
+ def inner_hash
107
+ @hash
108
+ end
109
+
110
+ end
111
+
112
+