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.
@@ -79,8 +79,9 @@ module Ramen::Metadata
79
79
  #
80
80
  def inspect
81
81
  children = []
82
- @schemas.each_by_id do |id,schema|
83
- children << (id.to_s+':'+schema.schema_name)
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.each_by_id do |id,table|
57
- children << (id.to_s+':'+table.table_name)
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 )
@@ -177,8 +177,9 @@ module Ramen::Metadata
177
177
  #
178
178
  def inspect
179
179
  children = []
180
- @columns.each_by_id do |id,col|
181
- children << (id.to_s+':'+col.column_name)
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
@@ -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 and id. By default, the
9
- # name and id attributes are derived from the class name of the type
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 :some_class_id, :some_class_name
15
- # def initialize( id, name )
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(1,'One') )
22
- # hash['One'] #=> #<SomeClass @some_class_id=1 @some_class_name='One'>
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*_id and *prefix*_name. Where
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
- # foreign_key_id and foreign_key_name.
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.each_by_id do |key, value|
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
@@ -10,7 +10,7 @@ module Ramen
10
10
  module Version
11
11
  MAJOR = 0
12
12
  MINOR = 4
13
- REVISION = 1
13
+ REVISION = 2
14
14
  STRING = [MAJOR, MINOR, REVISION].join('.')
15
15
  end
16
16
  end
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.0 SQL Server 2005 and MySQL 5.0.
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)
@@ -1,4 +1,4 @@
1
- DROP DATABASE IF EXISTS RamenTestSchema;
1
+ DROP DATABASE IF EXISTS RamenTestSchema;
2
2
  DROP DATABASE IF EXISTS RamenTestSchema2;
3
3
 
4
4
  CREATE DATABASE RamenTestSchema;
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
- if fk.respond_to? :foreign_key_id
275
- assert_equal( 4, fk.column.size )
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 )
@@ -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( id, name )
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( 1, 'One' )
21
- @obj2 = ObjToStoreInHash.new( 2, 'Two' )
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 test_each_by_name
48
- @collection.each_by_name do |name,value|
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.1
7
- date: 2008-04-28 00:00:00 -05:00
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