rtm-activerecord 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/DISCLAIMER +13 -0
- data/LICENSE +201 -0
- data/README +4 -0
- data/lib/rtm/activerecord/001_initial_schema.rb +119 -0
- data/lib/rtm/activerecord/association_and_role.rb +54 -0
- data/lib/rtm/activerecord/base.rb +83 -0
- data/lib/rtm/activerecord/connect.rb +106 -0
- data/lib/rtm/activerecord/io/from_xtm2.rb +266 -0
- data/lib/rtm/activerecord/io/from_xtm2_libxml.rb +97 -0
- data/lib/rtm/activerecord/io/to_jtm.rb +141 -0
- data/lib/rtm/activerecord/io/to_string.rb +130 -0
- data/lib/rtm/activerecord/io/to_xtm1.rb +162 -0
- data/lib/rtm/activerecord/io/to_xtm2.rb +163 -0
- data/lib/rtm/activerecord/io/to_yaml.rb +132 -0
- data/lib/rtm/activerecord/literal_index.rb +38 -0
- data/lib/rtm/activerecord/locators.rb +58 -0
- data/lib/rtm/activerecord/merging.rb +310 -0
- data/lib/rtm/activerecord/name_variant_occurrence.rb +86 -0
- data/lib/rtm/activerecord/persistent_code_output.rb +22 -0
- data/lib/rtm/activerecord/quaaxtm2rtm.rb +116 -0
- data/lib/rtm/activerecord/quaaxtm2rtmviews.rb +137 -0
- data/lib/rtm/activerecord/set_wrapper.rb +101 -0
- data/lib/rtm/activerecord/sugar/association/hash_access.rb +22 -0
- data/lib/rtm/activerecord/sugar/role/counterparts.rb +56 -0
- data/lib/rtm/activerecord/sugar/topic/characteristics.rb +15 -0
- data/lib/rtm/activerecord/sugar/topic/counterparts.rb +18 -0
- data/lib/rtm/activerecord/sugar/topic/hash_access.rb +78 -0
- data/lib/rtm/activerecord/sugar/topic/identifier_direct.rb +14 -0
- data/lib/rtm/activerecord/sugar/topic/predefined_associations.rb +53 -0
- data/lib/rtm/activerecord/tm_construct.rb +66 -0
- data/lib/rtm/activerecord/tm_delegator.rb +417 -0
- data/lib/rtm/activerecord/tm_set_delegator.rb +226 -0
- data/lib/rtm/activerecord/tmdm.rb +309 -0
- data/lib/rtm/activerecord/topic.rb +204 -0
- data/lib/rtm/activerecord/topic_map.rb +435 -0
- data/lib/rtm/activerecord/traverse_associations.rb +90 -0
- data/lib/rtm/activerecord.rb +106 -0
- metadata +120 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM::AR
|
5
|
+
module TraverseAssociations
|
6
|
+
# defines methods to traverse a specific assocation for all topics
|
7
|
+
def define_association(prop, options={})
|
8
|
+
r = options[:rule]
|
9
|
+
module_eval(<<-EOS, "(__AR_DELEGATOR_DEFINE_ASSOCIATION__)", 1)
|
10
|
+
def direct_#{prop}_roles
|
11
|
+
# prefetch typing topics
|
12
|
+
rtype = @ips_#{prop}_rtype ||= self.topic_map.get("#{r[:role_type]}")
|
13
|
+
atype = @ips_#{prop}_atype ||= self.topic_map.get("#{r[:association_type]}")
|
14
|
+
otype = @ips_#{prop}_otype ||= self.topic_map.get("#{r[:other_role_type]}")
|
15
|
+
# return nothing if any of the typing topics does not exist
|
16
|
+
return [] unless rtype && atype && otype
|
17
|
+
# we do that only here and not earlier because some might me nil
|
18
|
+
rtype = rtype.id
|
19
|
+
atype = atype.id
|
20
|
+
otype = otype.id
|
21
|
+
self.__getobj__.roles.map{|r|
|
22
|
+
r.ttype_id != nil &&
|
23
|
+
r.ttype_id == rtype &&
|
24
|
+
r.parent.roles.size == #{r[:association_arity]} &&
|
25
|
+
r.parent != nil &&
|
26
|
+
r.parent.ttype_id == atype &&
|
27
|
+
(r2 = r.parent.roles.select{|r2| r2.ttype_id != nil &&
|
28
|
+
r2.ttype_id == otype}.first) &&
|
29
|
+
r2}.select{|r2| r2}.map{|r2| AssociationRole.wrap(r2)}
|
30
|
+
end
|
31
|
+
def direct_#{prop}
|
32
|
+
direct_#{prop}_roles.map{|r2| r2.player}.uniq
|
33
|
+
end
|
34
|
+
EOS
|
35
|
+
|
36
|
+
if r[:transitive]
|
37
|
+
module_eval(<<-EOS, "(__AR_DELEGATOR_DEFINE_ASSOCIATION2__)", 1)
|
38
|
+
def #{prop}
|
39
|
+
d = todo = self.direct_#{prop}
|
40
|
+
while todo.size > 0
|
41
|
+
todo = todo.map{|dt| dt.direct_#{prop}}.flatten.uniq - d
|
42
|
+
d += todo
|
43
|
+
end
|
44
|
+
d
|
45
|
+
#d2 = self.direct_#{prop}.map {|dt| dt.#{prop}}.flatten
|
46
|
+
#(d+d2).uniq
|
47
|
+
end
|
48
|
+
EOS
|
49
|
+
else
|
50
|
+
if r[:infer] && r[:infer_other] # this part is not testet at all!
|
51
|
+
module_eval(<<-EOS, "(__AR_DELEGATOR_DEFINE_ASSOCIATION3a__)", 1)
|
52
|
+
def #{prop}
|
53
|
+
dps = (self + self.#{r[:infer]}).flatten.uniq
|
54
|
+
dcps = dps.map{|d2| d2.direct_#{prop}}
|
55
|
+
(dcps + dcps.map{|d2| d2.#{r[:infer_other]}}).flatten.uniq
|
56
|
+
end
|
57
|
+
EOS
|
58
|
+
elsif r[:infer]
|
59
|
+
module_eval(<<-EOS, "(__AR_DELEGATOR_DEFINE_ASSOCIATION3__)", 1)
|
60
|
+
def #{prop}
|
61
|
+
(self.direct_#{prop} + self.#{r[:infer]}.map{|d2| d2.direct_#{prop}}).flatten.uniq
|
62
|
+
end
|
63
|
+
EOS
|
64
|
+
elsif r[:infer_other]
|
65
|
+
module_eval(<<-EOS, "(__AR_DELEGATOR_DEFINE_ASSOCIATION4__)", 1)
|
66
|
+
def #{prop}
|
67
|
+
d = self.direct_#{prop}
|
68
|
+
(d + d.map{|d2| d2.#{r[:infer_other]}}).flatten.uniq
|
69
|
+
end
|
70
|
+
EOS
|
71
|
+
end
|
72
|
+
end
|
73
|
+
if r[:add]
|
74
|
+
module_eval(<<-EOS, "(__AR_DELEGATOR_DEFINE_ASSOCIATION_ADD_REMOVE__)", 1)
|
75
|
+
def add_#{r[:add]}(t)
|
76
|
+
a = self.topic_map.create_association("#{r[:association_type]}")
|
77
|
+
a.create_role self, "#{r[:role_type]}"
|
78
|
+
a.create_role t, "#{r[:other_role_type]}"
|
79
|
+
a
|
80
|
+
# TODO add_x in define_association needs to trigger reload of the topics somewhere
|
81
|
+
end
|
82
|
+
def remove_#{r[:add]}(t)
|
83
|
+
direct_#{prop}_roles.select{|r| r.player == t}.each{|r| r.parent.remove}
|
84
|
+
# TODO remove_x in define_association needs to trigger reload of the topics somewhere
|
85
|
+
end
|
86
|
+
EOS
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rtm'
|
6
|
+
rescue LoadError
|
7
|
+
rtm_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm/lib"))
|
8
|
+
if File.directory?(rtm_path)
|
9
|
+
$:.unshift rtm_path
|
10
|
+
require 'rtm'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
15
|
+
|
16
|
+
# class Class
|
17
|
+
# alias :rtm_old_const_missing :const_missing
|
18
|
+
# def const_missing(*const_name,&b)
|
19
|
+
# # puts "Constant missing: #{const_name.first.inspect}"
|
20
|
+
# rtm_old_const_missing(*const_name,&b)
|
21
|
+
# # puts "Constant missing: #{const_name.first.inspect}"
|
22
|
+
#
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
|
26
|
+
module RTM
|
27
|
+
class ActiveRecordTM < Engine
|
28
|
+
identifier :activerecord
|
29
|
+
|
30
|
+
def initialize(params, *args)
|
31
|
+
super
|
32
|
+
|
33
|
+
# code from old monolithic rtm.rb
|
34
|
+
@instance = RTM::RTMAR.instance
|
35
|
+
@instance.connect *args
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(name, *args)
|
39
|
+
@instance.send(name, *args)
|
40
|
+
end
|
41
|
+
def respond_to?(name)
|
42
|
+
super.respond_to?(name) || @instance.respond_to?(name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module RTM::AR
|
48
|
+
module TraverseAssociations
|
49
|
+
end
|
50
|
+
require 'uri'
|
51
|
+
|
52
|
+
%w[
|
53
|
+
tmdm
|
54
|
+
persistent_code_output
|
55
|
+
tm_delegator
|
56
|
+
tm_set_delegator
|
57
|
+
tm_construct
|
58
|
+
topic_map
|
59
|
+
traverse_associations
|
60
|
+
topic
|
61
|
+
association_and_role
|
62
|
+
name_variant_occurrence
|
63
|
+
locators
|
64
|
+
set_wrapper
|
65
|
+
base
|
66
|
+
literal_index
|
67
|
+
].each {|f| require "rtm/activerecord/#{f}" }
|
68
|
+
require "rtm/connect"
|
69
|
+
require "rtm/helpers"
|
70
|
+
require "rtm/validation"
|
71
|
+
require "rtm/locator_helpers"
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
class Topic
|
77
|
+
require 'rtm/activerecord/sugar/topic/characteristics'
|
78
|
+
include RTM::AR::Sugar::Topic::Characteristics
|
79
|
+
require 'rtm/activerecord/sugar/topic/counterparts'
|
80
|
+
include RTM::AR::Sugar::Topic::Counterparts
|
81
|
+
require 'rtm/activerecord/sugar/topic/identifier_direct'
|
82
|
+
include RTM::AR::Sugar::Topic::IdentifierDirect
|
83
|
+
require 'rtm/activerecord/sugar/topic/hash_access'
|
84
|
+
include RTM::AR::Sugar::Topic::HashAccess
|
85
|
+
require 'rtm/activerecord/sugar/topic/predefined_associations'
|
86
|
+
include RTM::AR::Sugar::Topic::PredefinedAssociations
|
87
|
+
require "rtm/activerecord/io/to_xtm2"
|
88
|
+
require "rtm/activerecord/io/to_xtm1"
|
89
|
+
require "rtm/activerecord/io/to_yaml"
|
90
|
+
require "rtm/activerecord/io/to_string"
|
91
|
+
require "rtm/activerecord/io/to_jtm"
|
92
|
+
|
93
|
+
end
|
94
|
+
class Association
|
95
|
+
require 'rtm/activerecord/sugar/association/hash_access'
|
96
|
+
include RTM::AR::Sugar::Association::HashAccess
|
97
|
+
require 'rtm/activerecord/sugar/role/counterparts'
|
98
|
+
include RTM::AR::Sugar::Role::Counterparts
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtm-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Bock
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-05 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rtm
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activerecord
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.3.5
|
44
|
+
version:
|
45
|
+
description: " Ruby Topic Maps is a Topic Maps engine written in Ruby.\n This is the backend engine which holds all data in ActiveRecord objects.\n It's available on all ruby platforms but currently does not pass all specs.\n"
|
46
|
+
email: "#rtm+rtm-activerecord-gem-20100205@topicmapslab.de"
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- lib/rtm/activerecord/001_initial_schema.rb
|
55
|
+
- lib/rtm/activerecord/association_and_role.rb
|
56
|
+
- lib/rtm/activerecord/base.rb
|
57
|
+
- lib/rtm/activerecord/connect.rb
|
58
|
+
- lib/rtm/activerecord/io/from_xtm2.rb
|
59
|
+
- lib/rtm/activerecord/io/from_xtm2_libxml.rb
|
60
|
+
- lib/rtm/activerecord/io/to_jtm.rb
|
61
|
+
- lib/rtm/activerecord/io/to_string.rb
|
62
|
+
- lib/rtm/activerecord/io/to_xtm1.rb
|
63
|
+
- lib/rtm/activerecord/io/to_xtm2.rb
|
64
|
+
- lib/rtm/activerecord/io/to_yaml.rb
|
65
|
+
- lib/rtm/activerecord/literal_index.rb
|
66
|
+
- lib/rtm/activerecord/locators.rb
|
67
|
+
- lib/rtm/activerecord/merging.rb
|
68
|
+
- lib/rtm/activerecord/name_variant_occurrence.rb
|
69
|
+
- lib/rtm/activerecord/persistent_code_output.rb
|
70
|
+
- lib/rtm/activerecord/quaaxtm2rtm.rb
|
71
|
+
- lib/rtm/activerecord/quaaxtm2rtmviews.rb
|
72
|
+
- lib/rtm/activerecord/set_wrapper.rb
|
73
|
+
- lib/rtm/activerecord/sugar/association/hash_access.rb
|
74
|
+
- lib/rtm/activerecord/sugar/role/counterparts.rb
|
75
|
+
- lib/rtm/activerecord/sugar/topic/characteristics.rb
|
76
|
+
- lib/rtm/activerecord/sugar/topic/counterparts.rb
|
77
|
+
- lib/rtm/activerecord/sugar/topic/hash_access.rb
|
78
|
+
- lib/rtm/activerecord/sugar/topic/identifier_direct.rb
|
79
|
+
- lib/rtm/activerecord/sugar/topic/predefined_associations.rb
|
80
|
+
- lib/rtm/activerecord/tm_construct.rb
|
81
|
+
- lib/rtm/activerecord/tm_delegator.rb
|
82
|
+
- lib/rtm/activerecord/tm_set_delegator.rb
|
83
|
+
- lib/rtm/activerecord/tmdm.rb
|
84
|
+
- lib/rtm/activerecord/topic.rb
|
85
|
+
- lib/rtm/activerecord/topic_map.rb
|
86
|
+
- lib/rtm/activerecord/traverse_associations.rb
|
87
|
+
- lib/rtm/activerecord.rb
|
88
|
+
- LICENSE
|
89
|
+
- DISCLAIMER
|
90
|
+
- README
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://rtm.topicmapslab.de/
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: "0"
|
105
|
+
version:
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
version:
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project: rtm
|
115
|
+
rubygems_version: 1.3.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: "Ruby Topic Maps: Active Record Backend"
|
119
|
+
test_files: []
|
120
|
+
|