og 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ProjectInfo +2 -2
- data/doc/RELEASES +10 -0
- data/lib/glue/cacheable.rb +2 -2
- data/lib/glue/taggable.rb +29 -22
- data/lib/glue/tree.rb +0 -2
- data/lib/og.rb +17 -26
- data/lib/og/entity.rb +28 -3
- data/lib/og/ez/clause.rb +1 -1
- data/lib/og/relation.rb +3 -2
- data/lib/og/store/mysql.rb +42 -4
- data/lib/og/store/psql.rb +32 -0
- data/lib/og/store/sql.rb +19 -48
- data/lib/og/store/sqlite.rb +32 -0
- data/lib/og/validation.rb +2 -2
- data/test/og/CONFIG.rb +1 -1
- data/test/og/tc_ez.rb +37 -0
- data/test/og/tc_multi_validations.rb +5 -4
- data/test/og/tc_setup.rb +48 -0
- data/test/og/tc_sti_find.rb +35 -0
- metadata +94 -90
data/ProjectInfo
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
TITLE : &title Og
|
4
4
|
NAME : &pkg og
|
5
|
-
VERSION : '0.
|
5
|
+
VERSION : '0.31.0'
|
6
6
|
STATUS : beta
|
7
7
|
|
8
8
|
AUTHOR : George Moschovitis
|
@@ -21,7 +21,7 @@ RUBYFORGE:
|
|
21
21
|
USERNAME: 'gmosx'
|
22
22
|
|
23
23
|
DEPENDENCIES:
|
24
|
-
- [ glue, '= 0.
|
24
|
+
- [ glue, '= 0.31.0' ]
|
25
25
|
|
26
26
|
PACKAGE: !!package
|
27
27
|
distribute: [ gem, tgz, zip ]
|
data/doc/RELEASES
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== Version 0.31.0
|
2
|
+
|
3
|
+
* Increased size of ogtype field in STI tables to 50 from 30.
|
4
|
+
|
5
|
+
* Made Og (Mysql) respect the port option when creating and dropping databases.
|
6
|
+
|
7
|
+
* Added thread_safe to Og.setup options.
|
8
|
+
|
9
|
+
* Added #to_xml method to Og managed objects.
|
10
|
+
|
1
11
|
== Version 0.30.0
|
2
12
|
|
3
13
|
Another pragmatic release. The Nitro development team worked over
|
data/lib/glue/cacheable.rb
CHANGED
data/lib/glue/taggable.rb
CHANGED
@@ -2,6 +2,11 @@ require 'facet/inflect'
|
|
2
2
|
|
3
3
|
# The default Tag implementation. A tag attaches semantics to
|
4
4
|
# a given object.
|
5
|
+
#
|
6
|
+
# === Design
|
7
|
+
#
|
8
|
+
# Use camelcase names for tags.
|
9
|
+
#
|
5
10
|
#--
|
6
11
|
# FIXME: use index and char() instead of String.
|
7
12
|
#++
|
@@ -55,10 +60,8 @@ class Tag
|
|
55
60
|
@count -= 1
|
56
61
|
|
57
62
|
if @count > 0
|
58
|
-
p "-- dec ref count"
|
59
63
|
update_property :count
|
60
64
|
else
|
61
|
-
p "-- count = 0 -> delete"
|
62
65
|
self.delete()
|
63
66
|
end
|
64
67
|
end
|
@@ -170,24 +173,7 @@ module Taggable
|
|
170
173
|
# INTERSECTION (AND)
|
171
174
|
|
172
175
|
def find_with_tags(*names)
|
173
|
-
|
174
|
-
info = ogmanager.store.join_table_info(relation)
|
175
|
-
count = names.size
|
176
|
-
names = names.map { |n| ogmanager.store.quote(n) }.join(',')
|
177
|
-
sql = %{
|
178
|
-
SELECT *
|
179
|
-
FROM #{info[:owner_table]} AS o
|
180
|
-
WHERE o.oid IN (
|
181
|
-
SELECT j.#{info[:owner_key]}
|
182
|
-
FROM #{info[:target_table]} AS t
|
183
|
-
JOIN #{info[:table]} AS j
|
184
|
-
ON t.oid = j.#{info[:target_key]}
|
185
|
-
WHERE (t.name IN (#{names}))
|
186
|
-
GROUP BY j.#{info[:owner_key]}
|
187
|
-
HAVING COUNT(j.#{info[:owner_key]}) = #{count}
|
188
|
-
)
|
189
|
-
}
|
190
|
-
return self.select(sql)
|
176
|
+
return find_request(:all, names)
|
191
177
|
end
|
192
178
|
alias_method :find_with_tag, :find_with_tags
|
193
179
|
|
@@ -195,9 +181,29 @@ module Taggable
|
|
195
181
|
# UNION (OR)
|
196
182
|
|
197
183
|
def find_with_any_tag(*names)
|
198
|
-
|
184
|
+
return find_request(:any, names)
|
185
|
+
end
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
def find_request(request_type, names)
|
190
|
+
condition = ""
|
191
|
+
opt = names.last
|
192
|
+
if opt.is_a?(Hash)
|
193
|
+
names.pop
|
194
|
+
escaped_condition = ogmanager.store.prepare_statement(opt[:condition])
|
195
|
+
#escaped_condition = ogmanager.store.escape_condition(opt[:condition])
|
196
|
+
condition = "AND #{escaped_condition}"
|
197
|
+
end
|
198
|
+
|
199
|
+
relation = relations.detect {|r| r.name == :tags}
|
199
200
|
info = ogmanager.store.join_table_info(relation)
|
200
|
-
|
201
|
+
|
202
|
+
if request_type == :all
|
203
|
+
count = names.size
|
204
|
+
additionnal_code = "HAVING COUNT(j.#{info[:owner_key]}) = #{count}"
|
205
|
+
end
|
206
|
+
|
201
207
|
names = names.map { |n| ogmanager.store.quote(n) }.join(',')
|
202
208
|
sql = %{
|
203
209
|
SELECT *
|
@@ -209,6 +215,7 @@ module Taggable
|
|
209
215
|
ON t.oid = j.#{info[:target_key]}
|
210
216
|
WHERE (t.name IN (#{names}))
|
211
217
|
GROUP BY j.#{info[:owner_key]}
|
218
|
+
#{additionnal_code}
|
212
219
|
)
|
213
220
|
}
|
214
221
|
return self.select(sql)
|
data/lib/glue/tree.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
raise 'This is not working yet, do not require this file.'
|
4
4
|
|
5
|
-
require 'glue/attribute'
|
6
|
-
|
7
5
|
# A useful encapsulation of the nested intervals pattern for
|
8
6
|
# hierarchical SQL queries. Slightly adapted from the original
|
9
7
|
# article (http://www.dbazine.com/tropashko4.shtml)
|
data/lib/og.rb
CHANGED
@@ -43,7 +43,7 @@ module Og
|
|
43
43
|
|
44
44
|
# The version.
|
45
45
|
|
46
|
-
Version = '0.
|
46
|
+
Version = '0.31.0'
|
47
47
|
|
48
48
|
# Library path.
|
49
49
|
|
@@ -107,35 +107,35 @@ module Og
|
|
107
107
|
|
108
108
|
setting :unmanageable_classes, :default => [], :doc => 'Explicitly unmanageable classes'
|
109
109
|
|
110
|
-
#
|
110
|
+
# Pseudo type for binary data
|
111
111
|
|
112
|
-
|
112
|
+
class Blob; end
|
113
113
|
|
114
|
-
|
114
|
+
class << self
|
115
115
|
|
116
|
-
|
116
|
+
# The active manager
|
117
117
|
|
118
|
-
|
118
|
+
attr_accessor :manager
|
119
119
|
|
120
|
-
|
120
|
+
# thread safe state
|
121
121
|
|
122
|
-
|
122
|
+
attr_reader :thread_safe
|
123
123
|
|
124
124
|
# Helper method, useful to initialize Og.
|
125
125
|
# If no options are passed, sqlite is selected
|
126
126
|
# as the default store.
|
127
127
|
|
128
|
-
def setup(options = {
|
129
|
-
|
128
|
+
def setup(options = {})
|
129
|
+
options={:store => :sqlite}.update(options)
|
130
130
|
# This is a flag a store or manager can use to determine
|
131
131
|
# if it was being called by Og.setup to provide
|
132
132
|
# additional, faster or enhanced functionality.
|
133
133
|
|
134
134
|
options[:called_by_og_setup] = true if options[:called_by_og_setup].nil?
|
135
135
|
|
136
|
-
|
136
|
+
@thread_safe = options.fetch(:thread_safe, true)
|
137
137
|
|
138
|
-
m =
|
138
|
+
m = @manager = Manager.new(options)
|
139
139
|
m.manage_classes
|
140
140
|
|
141
141
|
# Allows functionality that requires a store is
|
@@ -145,15 +145,6 @@ module Og
|
|
145
145
|
# only used by the PostgreSQL store.
|
146
146
|
|
147
147
|
m.post_setup if options[:called_by_og_setup]
|
148
|
-
rescue Exception => ex
|
149
|
-
Logger.error "Og.setup had problems: #{ex.class} => #{ex.message}"
|
150
|
-
if $DBG
|
151
|
-
Logger.error ex.inspect
|
152
|
-
Logger.error ex.backtrace.join("\n")
|
153
|
-
exit
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
148
|
return m
|
158
149
|
end
|
159
150
|
alias_method :connect, :setup
|
@@ -164,21 +155,21 @@ module Og
|
|
164
155
|
# Helper method.
|
165
156
|
|
166
157
|
def escape(str)
|
167
|
-
|
158
|
+
@manager.store.escape(str)
|
168
159
|
end
|
169
160
|
|
170
161
|
# Quote the string.
|
171
162
|
|
172
163
|
def quote(str)
|
173
|
-
|
164
|
+
@manager.store.quote(str)
|
174
165
|
end
|
175
166
|
|
176
167
|
# Change thread_safe mode.
|
177
168
|
|
178
169
|
def thread_safe=(bool)
|
179
|
-
|
180
|
-
#
|
181
|
-
|
170
|
+
@thread_safe = bool
|
171
|
+
# @manager and @manager.class.managers.each { |m| m.initialize_store }
|
172
|
+
@thread_safe
|
182
173
|
end
|
183
174
|
end
|
184
175
|
|
data/lib/og/entity.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'facets/core/module/class_extension'
|
2
2
|
require 'facet/kernel/assign_with'
|
3
3
|
|
4
4
|
require 'glue/property'
|
@@ -6,6 +6,8 @@ require 'og/relation'
|
|
6
6
|
require 'og/ez/clause'
|
7
7
|
require 'og/ez/condition'
|
8
8
|
|
9
|
+
require 'rexml/document' # for to_xml
|
10
|
+
|
9
11
|
module Og
|
10
12
|
|
11
13
|
# Include this module to classes to make them managable by Og.
|
@@ -114,10 +116,32 @@ module EntityMixin
|
|
114
116
|
def og_clone(*args)
|
115
117
|
Og::Entity.clone(self,*args)
|
116
118
|
end
|
119
|
+
|
120
|
+
# convert Og object to REXML-Object
|
121
|
+
# example usage:
|
122
|
+
# User[1].to_rexml
|
123
|
+
|
124
|
+
def to_rexml
|
125
|
+
xml = REXML::Element.new(self.class.to_s.downcase)
|
126
|
+
xml.add_attribute("oid", self.oid.to_s)
|
127
|
+
self.class.properties.keys.each do |key|
|
128
|
+
xml << REXML::Element.new(key.to_s).add_text(self.send(key).to_s) unless key == :oid
|
129
|
+
end
|
130
|
+
return xml
|
131
|
+
end
|
132
|
+
alias_method :to_xml_dom, :to_rexml
|
133
|
+
|
134
|
+
# convert Og object to an XML-String
|
135
|
+
# example usage:
|
136
|
+
# User[1].to_xml
|
137
|
+
|
138
|
+
def to_xml
|
139
|
+
self.to_rexml.to_s
|
140
|
+
end
|
117
141
|
|
118
142
|
include RelationDSL
|
119
143
|
|
120
|
-
|
144
|
+
class_extension do
|
121
145
|
|
122
146
|
def create(*args)
|
123
147
|
obj = self.new(*args)
|
@@ -649,7 +673,7 @@ class Entity
|
|
649
673
|
|
650
674
|
def entity_from_string(str)
|
651
675
|
res = nil
|
652
|
-
Og.
|
676
|
+
Og::Manager.managed_classes.each do |klass|
|
653
677
|
if klass.name == str
|
654
678
|
res = klass
|
655
679
|
break
|
@@ -763,3 +787,4 @@ end
|
|
763
787
|
# * George Moschovitis <gm@navel.gr>
|
764
788
|
# * Tom Sawyer <transfire@gmail.com>
|
765
789
|
# * Rob Pitt <rob@motionpath.com>
|
790
|
+
# * Fabian Buch <fabian@fabian-buch.de>
|
data/lib/og/ez/clause.rb
CHANGED
data/lib/og/relation.rb
CHANGED
@@ -123,7 +123,7 @@ class Relation
|
|
123
123
|
def symbol_to_class(sym, owner_class)
|
124
124
|
c = owner_class.name.dup
|
125
125
|
c = "::" + c unless c =~ /::/
|
126
|
-
c.gsub!(
|
126
|
+
c.gsub!(/::[^:]*$/, '::')
|
127
127
|
c << sym.to_s
|
128
128
|
begin
|
129
129
|
return constant(c)
|
@@ -184,6 +184,7 @@ class Relation
|
|
184
184
|
if r.polymorphic?
|
185
185
|
|
186
186
|
target_dm = r.target_class.to_s.demodulize
|
187
|
+
|
187
188
|
r.owner_class.module_eval %{
|
188
189
|
class #{r.owner_class}::#{target_dm} < #{r.target_class}
|
189
190
|
end
|
@@ -260,7 +261,7 @@ module RelationDSL
|
|
260
261
|
|
261
262
|
inheritor(:relations, [], :+) #unless @relations
|
262
263
|
|
263
|
-
|
264
|
+
class_extension do
|
264
265
|
|
265
266
|
# === Examples
|
266
267
|
#
|
data/lib/og/store/mysql.rb
CHANGED
@@ -88,19 +88,25 @@ class MysqlStore < SqlStore
|
|
88
88
|
extend MysqlUtils
|
89
89
|
include MysqlUtils
|
90
90
|
|
91
|
+
DefaultPort = 3306
|
92
|
+
|
91
93
|
def self.create(options)
|
94
|
+
options[:port] ||= DefaultPort
|
92
95
|
# gmosx: system is used to avoid shell expansion.
|
93
|
-
system 'mysqladmin', '-f', "--user=#{options[:user]}",
|
94
|
-
"--password=#{options[:password]}",
|
96
|
+
system 'mysqladmin', '-f', "--user=#{options[:user]}",
|
97
|
+
"--password=#{options[:password]}",
|
95
98
|
"--host=#{options[:address]}",
|
96
|
-
|
99
|
+
"--port=#{options[:port]}",
|
100
|
+
'create', options[:name]
|
97
101
|
super
|
98
102
|
end
|
99
103
|
|
100
104
|
def self.destroy(options)
|
105
|
+
options[:port] ||= DefaultPort
|
101
106
|
system 'mysqladmin', '-f', "--user=#{options[:user]}",
|
102
|
-
"--password=#{options[:password]}", 'drop',
|
107
|
+
"--password=#{options[:password]}", 'drop',
|
103
108
|
"--host=#{options[:address]}",
|
109
|
+
"--port=#{options[:port]}",
|
104
110
|
options[:name]
|
105
111
|
super
|
106
112
|
end
|
@@ -200,6 +206,38 @@ class MysqlStore < SqlStore
|
|
200
206
|
@conn.affected_rows
|
201
207
|
end
|
202
208
|
|
209
|
+
# Deserialize one object from the ResultSet.
|
210
|
+
|
211
|
+
def read_one(res, klass, options = nil)
|
212
|
+
return nil if res.blank?
|
213
|
+
|
214
|
+
if options and join_relations = options[:include]
|
215
|
+
join_relations = [join_relations].flatten.collect do |n|
|
216
|
+
klass.relation(n)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
res_row = res.next
|
221
|
+
|
222
|
+
# causes STI classes to come back as the correct child class
|
223
|
+
# if accessed from the superclass.
|
224
|
+
|
225
|
+
klass = Og::Entity::entity_from_string(res_row[0]) if klass.schema_inheritance?
|
226
|
+
obj = klass.og_allocate(res_row, 0)
|
227
|
+
|
228
|
+
if options and options[:select]
|
229
|
+
read_row(obj, res, res_row, 0)
|
230
|
+
else
|
231
|
+
obj.og_read(res_row)
|
232
|
+
read_join_relations(obj, res_row, 0, join_relations) if join_relations
|
233
|
+
end
|
234
|
+
|
235
|
+
return obj
|
236
|
+
|
237
|
+
ensure
|
238
|
+
res.close
|
239
|
+
end
|
240
|
+
|
203
241
|
private
|
204
242
|
|
205
243
|
def create_table(klass)
|
data/lib/og/store/psql.rb
CHANGED
@@ -593,6 +593,38 @@ class PsqlStore < SqlStore
|
|
593
593
|
def post_setup
|
594
594
|
create_constraints
|
595
595
|
end
|
596
|
+
|
597
|
+
# Deserialize one object from the ResultSet.
|
598
|
+
|
599
|
+
def read_one(res, klass, options = nil)
|
600
|
+
return nil if res.blank?
|
601
|
+
|
602
|
+
if options and join_relations = options[:include]
|
603
|
+
join_relations = [join_relations].flatten.collect do |n|
|
604
|
+
klass.relation(n)
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
res_row = res.next
|
609
|
+
|
610
|
+
# causes STI classes to come back as the correct child class
|
611
|
+
# if accessed from the superclass.
|
612
|
+
|
613
|
+
klass = Og::Entity::entity_from_string(res_row.result.flatten[res_row.fieldnum('ogtype')]) if klass.schema_inheritance?
|
614
|
+
obj = klass.og_allocate(res_row, 0)
|
615
|
+
|
616
|
+
if options and options[:select]
|
617
|
+
read_row(obj, res, res_row, 0)
|
618
|
+
else
|
619
|
+
obj.og_read(res_row)
|
620
|
+
read_join_relations(obj, res_row, 0, join_relations) if join_relations
|
621
|
+
end
|
622
|
+
|
623
|
+
return obj
|
624
|
+
|
625
|
+
ensure
|
626
|
+
res.close
|
627
|
+
end
|
596
628
|
|
597
629
|
private
|
598
630
|
|
data/lib/og/store/sql.rb
CHANGED
@@ -5,6 +5,7 @@ require 'facet/kernel/constant'
|
|
5
5
|
require 'facet/string/capitalized'
|
6
6
|
require 'facet/ormsupport'
|
7
7
|
|
8
|
+
|
8
9
|
module Og
|
9
10
|
|
10
11
|
# A collection of useful SQL utilities.
|
@@ -536,7 +537,8 @@ class SqlStore < Store
|
|
536
537
|
values = []
|
537
538
|
res = query(sql)
|
538
539
|
res.each_row do |row, idx|
|
539
|
-
|
540
|
+
value = [ row[idx] ].flatten[0]
|
541
|
+
values << type_cast(return_type, value)
|
540
542
|
end
|
541
543
|
return values
|
542
544
|
else
|
@@ -628,6 +630,20 @@ class SqlStore < Store
|
|
628
630
|
# return affected rows.
|
629
631
|
end
|
630
632
|
|
633
|
+
#takes an array, the first parameter of which is a prepared statement
|
634
|
+
#style string; this handles parameter escaping.
|
635
|
+
def prepare_statement(condition)
|
636
|
+
if condition.is_a?(Array)
|
637
|
+
args = condition.dup
|
638
|
+
str = args.shift
|
639
|
+
# ? handles a single type.
|
640
|
+
# ?* handles an array.
|
641
|
+
args.each { |arg| str.sub!(/\?\*/, quotea(arg)); str.sub!(/\?/, quote(arg)) }
|
642
|
+
condition = str
|
643
|
+
end
|
644
|
+
condition
|
645
|
+
end
|
646
|
+
|
631
647
|
private
|
632
648
|
|
633
649
|
# Create the sql table where objects of this class are
|
@@ -702,7 +718,7 @@ private
|
|
702
718
|
# chain. So inject a special class ogtype field that
|
703
719
|
# holds the class name.
|
704
720
|
|
705
|
-
fields << "ogtype VARCHAR(
|
721
|
+
fields << "ogtype VARCHAR(50)"
|
706
722
|
end
|
707
723
|
|
708
724
|
for p in properties.values
|
@@ -1033,9 +1049,7 @@ private
|
|
1033
1049
|
# If an array is passed as a condition, use prepared
|
1034
1050
|
# statement style escaping.
|
1035
1051
|
|
1036
|
-
|
1037
|
-
condition = prepare_statement(condition)
|
1038
|
-
end
|
1052
|
+
condition = prepare_statement(condition)
|
1039
1053
|
|
1040
1054
|
sql << " WHERE #{condition}"
|
1041
1055
|
end
|
@@ -1053,17 +1067,6 @@ private
|
|
1053
1067
|
return sql
|
1054
1068
|
end
|
1055
1069
|
|
1056
|
-
#takes an array, the first parameter of which is a prepared statement
|
1057
|
-
#style string; this handles parameter escaping.
|
1058
|
-
def prepare_statement(condition)
|
1059
|
-
args = condition.dup
|
1060
|
-
str = args.shift
|
1061
|
-
# ? handles a single type.
|
1062
|
-
# ?* handles an array.
|
1063
|
-
args.each { |arg| str.sub!(/\?\*/, quotea(arg)); str.sub!(/\?/, quote(arg)) }
|
1064
|
-
condition = str
|
1065
|
-
end
|
1066
|
-
|
1067
1070
|
# Subclasses can override this if they need some other order.
|
1068
1071
|
# This is needed because different backends require different
|
1069
1072
|
# order of the keywords.
|
@@ -1109,38 +1112,6 @@ private
|
|
1109
1112
|
end
|
1110
1113
|
end
|
1111
1114
|
|
1112
|
-
# Deserialize one object from the ResultSet.
|
1113
|
-
|
1114
|
-
def read_one(res, klass, options = nil)
|
1115
|
-
return nil if res.blank?
|
1116
|
-
|
1117
|
-
if options and join_relations = options[:include]
|
1118
|
-
join_relations = [join_relations].flatten.collect do |n|
|
1119
|
-
klass.relation(n)
|
1120
|
-
end
|
1121
|
-
end
|
1122
|
-
|
1123
|
-
res_row = res.next
|
1124
|
-
|
1125
|
-
# causes STI classes to come back as the correct child class
|
1126
|
-
# if accessed from the superclass.
|
1127
|
-
|
1128
|
-
klass = Og::Entity::entity_from_string(res_row.result.flatten[res_row.fieldnum('ogtype')]) if klass.schema_inheritance?
|
1129
|
-
obj = klass.og_allocate(res_row, 0)
|
1130
|
-
|
1131
|
-
if options and options[:select]
|
1132
|
-
read_row(obj, res, res_row, 0)
|
1133
|
-
else
|
1134
|
-
obj.og_read(res_row)
|
1135
|
-
read_join_relations(obj, res_row, 0, join_relations) if join_relations
|
1136
|
-
end
|
1137
|
-
|
1138
|
-
return obj
|
1139
|
-
|
1140
|
-
ensure
|
1141
|
-
res.close
|
1142
|
-
end
|
1143
|
-
|
1144
1115
|
# Deserialize all objects from the ResultSet.
|
1145
1116
|
|
1146
1117
|
def read_all(res, klass, options = nil)
|
data/lib/og/store/sqlite.rb
CHANGED
@@ -131,6 +131,38 @@ class SqliteStore < SqlStore
|
|
131
131
|
rows.map { |r| r[idx] }
|
132
132
|
end
|
133
133
|
|
134
|
+
# Deserialize one object from the ResultSet.
|
135
|
+
|
136
|
+
def read_one(res, klass, options = nil)
|
137
|
+
return nil if res.blank?
|
138
|
+
|
139
|
+
if options and join_relations = options[:include]
|
140
|
+
join_relations = [join_relations].flatten.collect do |n|
|
141
|
+
klass.relation(n)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
res_row = res.next
|
146
|
+
|
147
|
+
# causes STI classes to come back as the correct child class
|
148
|
+
# if accessed from the superclass.
|
149
|
+
|
150
|
+
klass = Og::Entity::entity_from_string(res_row[0]) if klass.schema_inheritance?
|
151
|
+
obj = klass.og_allocate(res_row, 0)
|
152
|
+
|
153
|
+
if options and options[:select]
|
154
|
+
read_row(obj, res, res_row, 0)
|
155
|
+
else
|
156
|
+
obj.og_read(res_row)
|
157
|
+
read_join_relations(obj, res_row, 0, join_relations) if join_relations
|
158
|
+
end
|
159
|
+
|
160
|
+
return obj
|
161
|
+
|
162
|
+
ensure
|
163
|
+
res.close
|
164
|
+
end
|
165
|
+
|
134
166
|
private
|
135
167
|
|
136
168
|
def property_to_field(klass, p)
|
data/lib/og/validation.rb
CHANGED
@@ -10,8 +10,8 @@ module Validation
|
|
10
10
|
# Encapsulates a list of validation errors.
|
11
11
|
|
12
12
|
class Errors
|
13
|
-
|
14
|
-
|
13
|
+
setting :invalid_relation, :default => 'Invalid relations'
|
14
|
+
setting :not_unique, :default => 'The value is already used'
|
15
15
|
end
|
16
16
|
|
17
17
|
module ClassMethods
|
data/test/og/CONFIG.rb
CHANGED
data/test/og/tc_ez.rb
CHANGED
@@ -60,3 +60,40 @@ class TC_EZ_STI < Test::Unit::TestCase # :nodoc: all
|
|
60
60
|
assert(results.empty?)
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
class TC_EZ_TrueClass < Test::Unit::TestCase # :nodoc: all
|
65
|
+
class Animal
|
66
|
+
property :mammal, TrueClass
|
67
|
+
end
|
68
|
+
|
69
|
+
$og1.manage_classes(Animal)
|
70
|
+
|
71
|
+
def test_for_null
|
72
|
+
2.times do
|
73
|
+
animal = Animal.new
|
74
|
+
animal.mammal = true
|
75
|
+
animal.save
|
76
|
+
|
77
|
+
animal = Animal.new
|
78
|
+
animal.mammal = false
|
79
|
+
animal.save
|
80
|
+
end
|
81
|
+
|
82
|
+
rubyish = ezish = nil
|
83
|
+
|
84
|
+
assert_nothing_raised do
|
85
|
+
rubyish = {
|
86
|
+
:true => Animal.all.select{|a| a.mammal}.map{|a| a.oid},
|
87
|
+
:false => Animal.all.reject{|a| a.mammal}.map{|a| a.oid}
|
88
|
+
}
|
89
|
+
|
90
|
+
ezish = {
|
91
|
+
:true => Animal.find{|animal| animal.mammal! == :null }.map{|a| a.oid},
|
92
|
+
:false => Animal.find{|animal| animal.mammal == :null }.map{|a| a.oid}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
assert_equal rubyish[:true], ezish[:true]
|
97
|
+
assert_equal rubyish[:false], ezish[:false]
|
98
|
+
end
|
99
|
+
end
|
@@ -9,11 +9,12 @@ require 'og/validation'
|
|
9
9
|
|
10
10
|
class TC_MultiValidation < Test::Unit::TestCase # :nodoc: all
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
MultiValidationsModel = File.expand_path(File.join(File.dirname(__FILE__), 'multi_validations_model.rb'))
|
13
|
+
|
14
|
+
def test_all
|
15
|
+
load MultiValidationsModel
|
15
16
|
assert_equal 2, TC_MultiValidation::User.validations.size
|
16
|
-
load
|
17
|
+
load MultiValidationsModel
|
17
18
|
assert_equal 2, TC_MultiValidation::User.validations.size
|
18
19
|
end
|
19
20
|
|
data/test/og/tc_setup.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..','..','..','glycerin' )
|
2
|
+
require 'test/unit'
|
3
|
+
require 'og'
|
4
|
+
|
5
|
+
class TCOg_setup < Test::Unit::TestCase # :nodoc: all
|
6
|
+
MockManager=Struct.new :options, :manage_classes, :post_setup
|
7
|
+
|
8
|
+
def test_default
|
9
|
+
manager= Og.setup
|
10
|
+
assert_instance_of Og::Manager, manager
|
11
|
+
assert_equal :sqlite, manager.options[:store]
|
12
|
+
assert_equal 'data', manager.options[:name]
|
13
|
+
assert_equal true, manager.options[:called_by_og_setup]
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_mattrs_initialized
|
17
|
+
manager= Og.setup
|
18
|
+
assert_equal manager,Og.manager
|
19
|
+
assert Og.thread_safe
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_missing_store
|
23
|
+
assert_raises(LoadError){Og.setup(:store=>:missing)}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_setup_default_store_plus_options
|
27
|
+
manager=Og.setup(:evolve_schema=>true)
|
28
|
+
assert_instance_of Og::Manager, manager
|
29
|
+
assert_equal :sqlite, manager.options[:store]
|
30
|
+
assert_equal true, manager.options[:evolve_schema]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_calls_manager_methods
|
34
|
+
mock_manager=Struct.new :options, :called do
|
35
|
+
def manage_classes
|
36
|
+
self.called = [:mc]
|
37
|
+
end
|
38
|
+
def post_setup
|
39
|
+
self.called << :ps
|
40
|
+
end
|
41
|
+
end
|
42
|
+
old=Og::Manager
|
43
|
+
Og.const_set :Manager, mock_manager
|
44
|
+
manager=Og.setup
|
45
|
+
assert_equal [:mc, :ps],manager.called
|
46
|
+
Og.const_set :Manager, old
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'og'
|
7
|
+
|
8
|
+
class TC_SchemaInheritFindByName < Test::Unit::TestCase
|
9
|
+
class Foo
|
10
|
+
property :name
|
11
|
+
|
12
|
+
schema_inheritance
|
13
|
+
end
|
14
|
+
|
15
|
+
class FooBar < Foo; end
|
16
|
+
class BarFoo < Foo; end
|
17
|
+
|
18
|
+
$og1.manage_classes(Foo, FooBar, BarFoo)
|
19
|
+
|
20
|
+
def test_find_by_name
|
21
|
+
name = 'tt'
|
22
|
+
|
23
|
+
f= Foo.create
|
24
|
+
f.name= name
|
25
|
+
f.save
|
26
|
+
|
27
|
+
f1= nil
|
28
|
+
|
29
|
+
assert_nothing_raised do
|
30
|
+
f1 = Foo.find_by_name(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_equal(f, f1)
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: og
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.31.0
|
7
|
+
date: 2006-07-20 00:00:00 -07:00
|
8
8
|
summary: State of the art object-relational mapping system.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: gm@navel.gr
|
12
12
|
homepage: http://www.nitroproject.org
|
13
|
-
rubyforge_project:
|
13
|
+
rubyforge_project:
|
14
14
|
description:
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
@@ -22,119 +22,123 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.0.0
|
24
24
|
version:
|
25
|
-
platform:
|
25
|
+
platform: ruby
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
|
+
post_install_message:
|
28
29
|
authors:
|
29
30
|
- George Moschovitis
|
30
31
|
files:
|
31
|
-
- ProjectInfo
|
32
|
-
- INSTALL
|
33
|
-
- README
|
34
32
|
- doc
|
35
|
-
- examples
|
36
33
|
- lib
|
37
34
|
- test
|
38
|
-
-
|
39
|
-
-
|
40
|
-
- doc/AUTHORS
|
41
|
-
- doc/tutorial.txt
|
42
|
-
- doc/LICENSE
|
43
|
-
- doc/RELEASES
|
44
|
-
- doc/config.txt
|
45
|
-
- examples/README
|
46
|
-
- examples/run.rb
|
47
|
-
- examples/mysql_to_psql.rb
|
35
|
+
- .
|
36
|
+
- examples
|
48
37
|
- lib/og
|
49
38
|
- lib/glue
|
50
|
-
- lib/og.rb
|
51
39
|
- lib/og/ez
|
52
|
-
- lib/og/
|
53
|
-
- lib/og/entity.rb
|
54
|
-
- lib/og/errors.rb
|
55
|
-
- lib/og/evolution.rb
|
56
|
-
- lib/og/manager.rb
|
40
|
+
- lib/og/test
|
57
41
|
- lib/og/relation
|
58
42
|
- lib/og/store
|
59
|
-
- lib/og/relation.rb
|
60
|
-
- lib/og/test
|
61
|
-
- lib/og/store.rb
|
62
43
|
- lib/og/vendor
|
63
|
-
- lib/og/test.rb
|
64
|
-
- lib/og/types.rb
|
65
|
-
- lib/og/markers.rb
|
66
|
-
- lib/og/validation.rb
|
67
|
-
- lib/og/ez/condition.rb
|
68
|
-
- lib/og/ez/clause.rb
|
69
|
-
- lib/og/relation/all.rb
|
70
|
-
- lib/og/relation/many_to_many.rb
|
71
|
-
- lib/og/relation/belongs_to.rb
|
72
|
-
- lib/og/relation/has_many.rb
|
73
|
-
- lib/og/relation/has_one.rb
|
74
|
-
- lib/og/relation/joins_many.rb
|
75
|
-
- lib/og/relation/refers_to.rb
|
76
44
|
- lib/og/store/alpha
|
77
|
-
- lib/og/store/kirby.rb
|
78
|
-
- lib/og/store/mysql.rb
|
79
|
-
- lib/og/store/psql.rb
|
80
|
-
- lib/og/store/sql.rb
|
81
|
-
- lib/og/store/sqlite.rb
|
82
|
-
- lib/og/store/sqlite2.rb
|
83
|
-
- lib/og/store/alpha/sqlserver.rb
|
84
|
-
- lib/og/store/alpha/filesys.rb
|
85
|
-
- lib/og/store/alpha/memory.rb
|
86
|
-
- lib/og/test/assertions.rb
|
87
|
-
- lib/og/test/testcase.rb
|
88
|
-
- lib/og/vendor/mysql.rb
|
89
|
-
- lib/og/vendor/README
|
90
|
-
- lib/glue/hierarchical.rb
|
91
|
-
- lib/glue/orderable.rb
|
92
|
-
- lib/glue/optimistic_locking.rb
|
93
|
-
- lib/glue/revisable.rb
|
94
|
-
- lib/glue/taggable.rb
|
95
|
-
- lib/glue/timestamped.rb
|
96
|
-
- lib/glue/tree.rb
|
97
|
-
- lib/glue/searchable.rb
|
98
|
-
- lib/glue/cacheable.rb
|
99
45
|
- test/og
|
100
46
|
- test/glue
|
101
47
|
- test/og/mixin
|
102
|
-
- test/og/CONFIG.rb
|
103
48
|
- test/og/store
|
104
|
-
- test/og/tc_delete_all.rb
|
105
|
-
- test/og/tc_inheritance.rb
|
106
|
-
- test/og/tc_join.rb
|
107
49
|
- test/og/tc_multiple.rb
|
108
|
-
- test/og/
|
109
|
-
- test/og/
|
110
|
-
- test/og/tc_relation.rb
|
111
|
-
- test/og/tc_reverse.rb
|
112
|
-
- test/og/tc_select.rb
|
50
|
+
- test/og/mixin/tc_timestamped.rb
|
51
|
+
- test/og/tc_validation2.rb
|
113
52
|
- test/og/tc_store.rb
|
114
53
|
- test/og/tc_types.rb
|
115
|
-
-
|
54
|
+
- doc/CHANGELOG.1
|
55
|
+
- lib/og/test/testcase.rb
|
56
|
+
- lib/og/markers.rb
|
57
|
+
- lib/og/relation/refers_to.rb
|
58
|
+
- test/og/store/tc_filesys.rb
|
59
|
+
- test/og/tc_inheritance.rb
|
60
|
+
- doc/RELEASES
|
61
|
+
- test/og/tc_cacheable.rb
|
62
|
+
- lib/og/store/alpha/sqlserver.rb
|
63
|
+
- INSTALL
|
64
|
+
- test/og/tc_relation.rb
|
65
|
+
- examples/README
|
66
|
+
- lib/og/relation/has_many.rb
|
67
|
+
- lib/glue/optimistic_locking.rb
|
116
68
|
- test/og/tc_scoped.rb
|
117
|
-
-
|
118
|
-
- test/og/
|
119
|
-
-
|
120
|
-
-
|
69
|
+
- examples/run.rb
|
70
|
+
- test/og/multi_validations_model.rb
|
71
|
+
- lib/og/ez/condition.rb
|
72
|
+
- lib/og/store/psql.rb
|
73
|
+
- lib/og/relation.rb
|
74
|
+
- lib/og/validation.rb
|
121
75
|
- test/og/tc_multi_validations.rb
|
122
|
-
-
|
123
|
-
- test/og/tc_validation_loop.rb
|
76
|
+
- lib/og/vendor/README
|
124
77
|
- test/og/tc_resolve.rb
|
125
|
-
-
|
126
|
-
- test/og/
|
78
|
+
- doc/LICENSE
|
79
|
+
- test/og/tc_validation_loop.rb
|
80
|
+
- lib/og/collection.rb
|
81
|
+
- lib/og/store/sqlite2.rb
|
82
|
+
- test/og/tc_join.rb
|
83
|
+
- lib/glue/hierarchical.rb
|
84
|
+
- lib/og/store/mysql.rb
|
85
|
+
- lib/og/relation/joins_many.rb
|
86
|
+
- lib/og/store/kirby.rb
|
87
|
+
- test/og/tc_select.rb
|
88
|
+
- doc/config.txt
|
89
|
+
- lib/og/test.rb
|
90
|
+
- lib/og/evolution.rb
|
91
|
+
- lib/og/relation/all.rb
|
92
|
+
- lib/og/relation/has_one.rb
|
93
|
+
- lib/og/store/alpha/filesys.rb
|
94
|
+
- lib/og/relation/belongs_to.rb
|
95
|
+
- test/og/mixin/tc_hierarchical.rb
|
96
|
+
- test/og/tc_reverse.rb
|
97
|
+
- test/og/tc_finder.rb
|
98
|
+
- test/og/tc_delete_all.rb
|
99
|
+
- doc/tutorial.txt
|
100
|
+
- test/glue/tc_revisable.rb
|
101
|
+
- test/og/tc_setup.rb
|
102
|
+
- test/og/tc_override.rb
|
103
|
+
- doc/AUTHORS
|
104
|
+
- README
|
105
|
+
- lib/glue/taggable.rb
|
106
|
+
- test/og/store/tc_sti.rb
|
107
|
+
- lib/og/errors.rb
|
108
|
+
- test/og/tc_polymorphic.rb
|
109
|
+
- lib/glue/timestamped.rb
|
110
|
+
- lib/og/entity.rb
|
111
|
+
- setup.rb
|
112
|
+
- test/og/tc_inheritance2.rb
|
113
|
+
- ProjectInfo
|
114
|
+
- lib/glue/tree.rb
|
115
|
+
- lib/og/relation/many_to_many.rb
|
116
|
+
- lib/og/store/sql.rb
|
117
|
+
- lib/glue/cacheable.rb
|
118
|
+
- examples/mysql_to_psql.rb
|
119
|
+
- test/og/store/tc_kirby.rb
|
127
120
|
- test/og/tc_aggregations_calculations.rb
|
121
|
+
- lib/og/vendor/mysql.rb
|
128
122
|
- test/og/tc_camel_case_join.rb
|
129
|
-
-
|
130
|
-
-
|
131
|
-
- test/og/mixin/tc_optimistic_locking.rb
|
123
|
+
- lib/og/store.rb
|
124
|
+
- lib/og/types.rb
|
132
125
|
- test/og/mixin/tc_taggable.rb
|
133
|
-
- test/og/mixin/
|
134
|
-
- test/og/
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
126
|
+
- test/og/mixin/tc_optimistic_locking.rb
|
127
|
+
- test/og/tc_sti_find.rb
|
128
|
+
- lib/og/manager.rb
|
129
|
+
- lib/og/test/assertions.rb
|
130
|
+
- lib/glue/orderable.rb
|
131
|
+
- test/og/CONFIG.rb
|
132
|
+
- lib/glue/revisable.rb
|
133
|
+
- test/og/mixin/tc_orderable.rb
|
134
|
+
- test/og/tc_accumulator.rb
|
135
|
+
- lib/og.rb
|
136
|
+
- lib/glue/searchable.rb
|
137
|
+
- test/og/tc_validation.rb
|
138
|
+
- test/og/tc_ez.rb
|
139
|
+
- lib/og/store/alpha/memory.rb
|
140
|
+
- lib/og/ez/clause.rb
|
141
|
+
- lib/og/store/sqlite.rb
|
138
142
|
test_files: []
|
139
143
|
|
140
144
|
rdoc_options: []
|
@@ -155,5 +159,5 @@ dependencies:
|
|
155
159
|
requirements:
|
156
160
|
- - "="
|
157
161
|
- !ruby/object:Gem::Version
|
158
|
-
version: 0.
|
162
|
+
version: 0.31.0
|
159
163
|
version:
|