ramen 0.4.1 → 0.4.2
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/lib/ramen/metadata/database.rb +3 -2
- data/lib/ramen/metadata/schema.rb +3 -3
- data/lib/ramen/metadata/table.rb +3 -2
- data/lib/ramen/ramen_hash.rb +10 -52
- data/lib/ramen/version.rb +1 -1
- data/readme.txt +1 -1
- data/test/mysql_create_test_db.sql +1 -1
- data/test/test_ramen.rb +2 -11
- data/test/test_ramen_hash.rb +5 -21
- metadata +2 -2
|
@@ -79,8 +79,9 @@ module Ramen::Metadata
|
|
|
79
79
|
#
|
|
80
80
|
def inspect
|
|
81
81
|
children = []
|
|
82
|
-
@schemas.
|
|
83
|
-
|
|
82
|
+
@schemas.each do |schema_name,schema|
|
|
83
|
+
prefix = (schema.respond_to?:schema_id)? schema.schema_id.to_s+':' : ''
|
|
84
|
+
children << (prefix+schema_name)
|
|
84
85
|
end
|
|
85
86
|
to_s[0..-2]+' schema=['+children.join(', ')+']>'
|
|
86
87
|
end
|
|
@@ -53,8 +53,9 @@ module Ramen::Metadata
|
|
|
53
53
|
#
|
|
54
54
|
def inspect
|
|
55
55
|
children = []
|
|
56
|
-
@tables.
|
|
57
|
-
|
|
56
|
+
@tables.each do |table_name,table|
|
|
57
|
+
prefix = (table.respond_to?:table_id) ? table.table_id.to_s+':' : ''
|
|
58
|
+
children << (prefix+table_name)
|
|
58
59
|
end
|
|
59
60
|
to_s[0..-2]+' schema_name=\''+ schema_name+ '\'' + ((self.respond_to?:schema_id)?' schema_id=' + schema_id.to_s : '') + ' tables=['+children.join(', ')+']>'
|
|
60
61
|
end
|
|
@@ -62,7 +63,6 @@ module Ramen::Metadata
|
|
|
62
63
|
# :section: Internal Methods
|
|
63
64
|
# The following methods are for Ramen's internal use. They
|
|
64
65
|
# are not intended for clients of Ramen to use.
|
|
65
|
-
|
|
66
66
|
def initialize( record, database )
|
|
67
67
|
super(record, database)
|
|
68
68
|
@tables = Ramen::RamenHash.new( Table )
|
data/lib/ramen/metadata/table.rb
CHANGED
|
@@ -177,8 +177,9 @@ module Ramen::Metadata
|
|
|
177
177
|
#
|
|
178
178
|
def inspect
|
|
179
179
|
children = []
|
|
180
|
-
@columns.
|
|
181
|
-
|
|
180
|
+
@columns.each do |column_name, column|
|
|
181
|
+
prefix = (column.respond_to?:column_id) ? column.column_id.to_s+':' : ''
|
|
182
|
+
children << (prefix+column_name)
|
|
182
183
|
end
|
|
183
184
|
to_s[0..-2]+' '+table_name+' columns=['+children.join(', ')+']>'
|
|
184
185
|
end
|
data/lib/ramen/ramen_hash.rb
CHANGED
|
@@ -5,22 +5,20 @@
|
|
|
5
5
|
module Ramen
|
|
6
6
|
|
|
7
7
|
# A special hash that stores items of the same type.
|
|
8
|
-
# RamenHash indexes each item by its name
|
|
9
|
-
# name
|
|
8
|
+
# RamenHash indexes each item by its name. By default, the
|
|
9
|
+
# name attributes are derived from the class name of the type
|
|
10
10
|
# RamenHash will collect.
|
|
11
11
|
#
|
|
12
12
|
# usage:
|
|
13
13
|
# def SomeClass
|
|
14
|
-
# attr_accessor :
|
|
15
|
-
# def initialize(
|
|
16
|
-
# @some_class_id = id
|
|
14
|
+
# attr_accessor :some_class_name
|
|
15
|
+
# def initialize( name )
|
|
17
16
|
# @some_class_name = name
|
|
18
17
|
# end
|
|
19
18
|
# end
|
|
20
19
|
# hash = RamenHash.new( SomeClass )
|
|
21
|
-
# hash.add( SomeClass.new(
|
|
22
|
-
# hash['One'] #=> #<SomeClass @
|
|
23
|
-
# hash[1] #=> #<SomeClass @some_class_id=1 @some_class_name='One'>
|
|
20
|
+
# hash.add( SomeClass.new('One') )
|
|
21
|
+
# hash['One'] #=> #<SomeClass @some_class_name='One'>
|
|
24
22
|
#
|
|
25
23
|
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-ramen_hash_rb.html]
|
|
26
24
|
#
|
|
@@ -33,11 +31,11 @@ module Ramen
|
|
|
33
31
|
# [clazz] the type which RamenHash will store.
|
|
34
32
|
# [prefix] (optional) the attribute prefix for indexing.
|
|
35
33
|
#
|
|
36
|
-
# RamenHash indexes each obj by *prefix*
|
|
34
|
+
# RamenHash indexes each obj by *prefix*_name. Where
|
|
37
35
|
# prefix defaults to the clazz's name converted by String#to_delimited_words.
|
|
38
36
|
#
|
|
39
37
|
# For example for Ramen.new( ForeignKey ), the hash is indexed by
|
|
40
|
-
#
|
|
38
|
+
# foreign_key_name.
|
|
41
39
|
#
|
|
42
40
|
# RamenHash makes []= private since assignment to an index is not allowed.
|
|
43
41
|
# Use add( obj ) instead.
|
|
@@ -45,9 +43,7 @@ module Ramen
|
|
|
45
43
|
def initialize( clazz, prefix = nil )
|
|
46
44
|
prefix ||= clazz.name.match( /[^:]*$/ )[0].to_delimited_words
|
|
47
45
|
@clazz = clazz
|
|
48
|
-
@id = "#{prefix}_id".to_sym
|
|
49
46
|
@name = "#{prefix}_name".to_sym
|
|
50
|
-
@ids = []
|
|
51
47
|
@names = [] # TODO Change to SortedArray
|
|
52
48
|
end
|
|
53
49
|
|
|
@@ -63,13 +59,6 @@ module Ramen
|
|
|
63
59
|
raise RamenError, "can not add type to #RamenHash. type_added=#{obj.class}; type_allowed=#{@clazz}"
|
|
64
60
|
end
|
|
65
61
|
|
|
66
|
-
if obj.respond_to?(@id) then
|
|
67
|
-
id = obj.send(@id)
|
|
68
|
-
id = id.downcase if id.respond_to?(:downcase)
|
|
69
|
-
@ids << id
|
|
70
|
-
self[id]=obj
|
|
71
|
-
end
|
|
72
|
-
|
|
73
62
|
name = obj.send(@name)
|
|
74
63
|
name = name.downcase if name.respond_to?(:downcase)
|
|
75
64
|
@names << name
|
|
@@ -81,44 +70,13 @@ module Ramen
|
|
|
81
70
|
#
|
|
82
71
|
def each()
|
|
83
72
|
@names.each do |name|
|
|
84
|
-
yield self[name]
|
|
73
|
+
yield name, self[name]
|
|
85
74
|
end
|
|
86
75
|
end
|
|
87
76
|
|
|
88
|
-
def each_by( keys )
|
|
89
|
-
keys.each do |key|
|
|
90
|
-
yield key, self[key]
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
private :each_by
|
|
94
|
-
|
|
95
|
-
# calls the block, giving the block the item name and the item
|
|
96
|
-
#
|
|
97
|
-
# usage
|
|
98
|
-
# hash.each_by_name do |name, obj|
|
|
99
|
-
# puts name
|
|
100
|
-
# puts obj.inspect
|
|
101
|
-
# end
|
|
102
|
-
def each_by_name( &block )
|
|
103
|
-
each_by( @names, &block )
|
|
104
|
-
self
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# calls the block, giving the block the item id and the item
|
|
108
|
-
#
|
|
109
|
-
# usage
|
|
110
|
-
# hash.each_by_id do |id, obj|
|
|
111
|
-
# puts id
|
|
112
|
-
# puts obj.inspect
|
|
113
|
-
# end
|
|
114
|
-
def each_by_id( &block )
|
|
115
|
-
each_by( @ids, &block )
|
|
116
|
-
self
|
|
117
|
-
end
|
|
118
|
-
|
|
119
77
|
def to_s
|
|
120
78
|
results = []
|
|
121
|
-
self.
|
|
79
|
+
self.each do |key, value|
|
|
122
80
|
results << (key.to_s + ':' + self[key].send(@name) + '=>' + value.to_s)
|
|
123
81
|
end
|
|
124
82
|
results.join( ' ' )
|
data/lib/ramen/version.rb
CHANGED
data/readme.txt
CHANGED
|
@@ -5,7 +5,7 @@ Ramen creates an object model from your database's metadata (Schema, Tables,
|
|
|
5
5
|
Columns, Indexes, Keys). This metadata is sometimes called
|
|
6
6
|
_data_ _dictionary_, _system_ _catalog_, or _INFORMATION_ _SCHEMA_.
|
|
7
7
|
|
|
8
|
-
Version:: 0.4.
|
|
8
|
+
Version:: 0.4.2 SQL Server 2005 and MySQL 5.0.
|
|
9
9
|
|
|
10
10
|
What can you do with Ramen?
|
|
11
11
|
* Build a tool for generating test data (see Noodle on Rubyforge)
|
data/test/test_ramen.rb
CHANGED
|
@@ -86,11 +86,6 @@ class Test_Ramen < Test::Unit::TestCase
|
|
|
86
86
|
employee = db.schema['RamenTestSchema'].table['Employee']
|
|
87
87
|
assert_equal( 0, employee.is_published ) if employee.respond_to? :is_published #sql2005
|
|
88
88
|
assert_equal( 1, employee.auto_increment ) if employee.respond_to? :auto_increment # mysql
|
|
89
|
-
|
|
90
|
-
if employee.respond_to? :table_id then
|
|
91
|
-
employee = db.schema['RamenTestSchema'].table[employee.table_id]
|
|
92
|
-
assert_equal( 'Employee', employee.table_name )
|
|
93
|
-
end
|
|
94
89
|
end
|
|
95
90
|
|
|
96
91
|
def t_column_access( key, db )
|
|
@@ -271,12 +266,8 @@ class Test_Ramen < Test::Unit::TestCase
|
|
|
271
266
|
fk = table.fk['FK_MultiColumnFK_MultiColumnPK']
|
|
272
267
|
referenced_table = db.schema['RamenTestSchema'].table['MultiColumnPK']
|
|
273
268
|
assert_same( referenced_table, fk.referenced_table )
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
else
|
|
277
|
-
assert_equal( 2, fk.column.size )
|
|
278
|
-
assert_equal( ['fk1', 'fk2'], fk.column.keys.sort )
|
|
279
|
-
end
|
|
269
|
+
assert_equal( 2, fk.column.size )
|
|
270
|
+
assert_equal( ['fk1', 'fk2'], fk.column.keys.sort )
|
|
280
271
|
end
|
|
281
272
|
|
|
282
273
|
def t_belongs_to( key, db )
|
data/test/test_ramen_hash.rb
CHANGED
|
@@ -9,26 +9,22 @@ require 'lib/ramen'
|
|
|
9
9
|
module Ramen
|
|
10
10
|
class ObjToStoreInHash
|
|
11
11
|
attr_reader :obj_id, :obj_name
|
|
12
|
-
def initialize(
|
|
13
|
-
@obj_id = id
|
|
12
|
+
def initialize( name )
|
|
14
13
|
@obj_name = name
|
|
15
14
|
end
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
class TestRamenHash < Test::Unit::TestCase
|
|
19
18
|
def setup
|
|
20
|
-
@obj1 = ObjToStoreInHash.new(
|
|
21
|
-
@obj2 = ObjToStoreInHash.new(
|
|
19
|
+
@obj1 = ObjToStoreInHash.new( 'One' )
|
|
20
|
+
@obj2 = ObjToStoreInHash.new( 'Two' )
|
|
22
21
|
@collection = RamenHash.new( ObjToStoreInHash, 'obj' )
|
|
23
22
|
@collection.add( @obj1 )
|
|
24
23
|
@collection.add( @obj2 )
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
def test_hash
|
|
28
|
-
assert_equal(@obj1, @collection[1])
|
|
29
27
|
assert_equal(@obj1, @collection['One'])
|
|
30
|
-
|
|
31
|
-
assert_equal(@obj2, @collection[2])
|
|
32
28
|
assert_equal(@obj2, @collection['Two'])
|
|
33
29
|
end
|
|
34
30
|
|
|
@@ -44,25 +40,13 @@ module Ramen
|
|
|
44
40
|
end
|
|
45
41
|
end
|
|
46
42
|
|
|
47
|
-
def
|
|
48
|
-
@collection.
|
|
43
|
+
def test_each
|
|
44
|
+
@collection.each do |name,value|
|
|
49
45
|
assert( (['one','two'].include? name), "name must be either one or two, name=#{name}")
|
|
50
46
|
assert_same( @collection[name], value )
|
|
51
47
|
end
|
|
52
48
|
end
|
|
53
49
|
|
|
54
|
-
def test_each_by_id
|
|
55
|
-
@collection.each_by_id do |id,value|
|
|
56
|
-
assert( ([1,2].include? id), "id must be either 1 or 2, id=#{id}")
|
|
57
|
-
assert_same( @collection[id], value )
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_each
|
|
62
|
-
@collection.each do |obj|
|
|
63
|
-
assert( ([1,2].include? obj.obj_id), "id must be either 1 or 2, id=#{obj.obj_id}")
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
50
|
|
|
67
51
|
def test_to_s
|
|
68
52
|
# simply exercise to_s to ensure it doesn't throw exception
|
metadata
CHANGED
|
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: ramen
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.4.
|
|
7
|
-
date: 2008-
|
|
6
|
+
version: 0.4.2
|
|
7
|
+
date: 2008-05-20 00:00:00 -05:00
|
|
8
8
|
summary: Ramen, database reflection library. Easy access to the definition of schemas, tables, columns, indexes, and foreign keys.
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|