ramen 0.4.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.
Files changed (40) hide show
  1. data/doc/doc_resources/MetaData_Class_Diagram.gif +0 -0
  2. data/doc/doc_resources/MetaData_Class_Diagram.png +0 -0
  3. data/doc/doc_resources/Thumbs.db +0 -0
  4. data/lib/ramen/core.rb +75 -0
  5. data/lib/ramen/default_logger.rb +29 -0
  6. data/lib/ramen/engine/engine.rb +34 -0
  7. data/lib/ramen/engine/mysql.rb +225 -0
  8. data/lib/ramen/engine/sql2005.rb +377 -0
  9. data/lib/ramen/home.rb +162 -0
  10. data/lib/ramen/metadata/column.rb +38 -0
  11. data/lib/ramen/metadata/database.rb +137 -0
  12. data/lib/ramen/metadata/foreign_key.rb +71 -0
  13. data/lib/ramen/metadata/foreign_key_column.rb +51 -0
  14. data/lib/ramen/metadata/index.rb +71 -0
  15. data/lib/ramen/metadata/index_column.rb +49 -0
  16. data/lib/ramen/metadata/key_constraint.rb +56 -0
  17. data/lib/ramen/metadata/metadata.rb +10 -0
  18. data/lib/ramen/metadata/primary_key.rb +71 -0
  19. data/lib/ramen/metadata/primary_key_column.rb +49 -0
  20. data/lib/ramen/metadata/schema.rb +86 -0
  21. data/lib/ramen/metadata/table.rb +202 -0
  22. data/lib/ramen/ramen_error.rb +16 -0
  23. data/lib/ramen/ramen_hash.rb +143 -0
  24. data/lib/ramen/ramen_module.rb +52 -0
  25. data/lib/ramen/row_data_gateway.rb +89 -0
  26. data/lib/ramen/version.rb +16 -0
  27. data/lib/ramen.rb +62 -0
  28. data/readme.txt +159 -0
  29. data/test/config/config.yml +19 -0
  30. data/test/helper.rb +18 -0
  31. data/test/mysql_create_test_db.sql +47 -0
  32. data/test/sql2005_create_test_db.sql +45 -0
  33. data/test/test_bugs.rb +32 -0
  34. data/test/test_core.rb +63 -0
  35. data/test/test_default_logger.rb +38 -0
  36. data/test/test_home.rb +33 -0
  37. data/test/test_ramen.rb +274 -0
  38. data/test/test_ramen_hash.rb +78 -0
  39. data/test/test_ramen_module.rb +21 -0
  40. metadata +99 -0
@@ -0,0 +1,71 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+ module Ramen::Metadata
6
+
7
+ # ForeignKey contains meta-data about foreign keys within a Table.
8
+ # The attributes are database engine specific.
9
+ # Only foreign_key_name and foreign_key_id are required by Ramen.
10
+ # See RowDataGateway for more information.
11
+ #
12
+ # ForeignKey also contains a collection of ForeignKeyColumn objects. These
13
+ # are accessable by the column attribute.
14
+ #
15
+ # See Database for a description of how ForeignKey fits in the Ramen collection
16
+ # hierarchy.
17
+ #
18
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-foreign_key_rb.html]
19
+ #
20
+ class ForeignKey < Ramen::RowDataGateway
21
+ # :section: External Methods
22
+ # The following methods are intended for use by Ramen's clients.
23
+
24
+ # Comparison, returns -1,0,+1, compares foreign_key_name
25
+ def <=> other
26
+ Ramen::RowDataGateway.compare( foreign_key_name, other )
27
+ end
28
+
29
+ # column() #=> RamenHash reference
30
+ #
31
+ # This attribute provides access to a RamenHash of all ForeignKeyColumn objects
32
+ # in the ForeignKey. The hash is indexed by column_id and column_name.
33
+ #
34
+ # usage:
35
+ # require 'lib/ramen'
36
+ # db = Ramen.create( configuration )
37
+ # schema = db.schema['HumanResources']
38
+ # table = schema.table['Employee']
39
+ # fk = table.fk['FK_Employee_Contact_ContactID']
40
+ # fk_column = fk.column['ContactID'] #=> #<Ramen::ForeignKeyColumn ...
41
+ #
42
+ def column
43
+ @columns
44
+ end
45
+
46
+ # :section: Internal Methods
47
+ # The following methods are for Ramen's internal use. They
48
+ # are not intended for clients of Ramen to use.
49
+
50
+ def initialize( record, database )
51
+ super( record, database )
52
+ @columns = Ramen::RamenHash.new( ForeignKeyColumn, 'column' )
53
+ end
54
+
55
+ # add_to( database )
56
+ #
57
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
58
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
59
+ def add_to( database )
60
+ database.schema[ self.table_schema ].table[ self.table_name ].add_foreign_key( self )
61
+ end
62
+
63
+ # add_column( obj ) #=> obj
64
+ #
65
+ # Adds the column to this table. Throws a RamenError if the obj
66
+ # is not a ForeignKeyColumn.
67
+ def add_column( obj )
68
+ @columns.add( obj )
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,51 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+
6
+ module Ramen::Metadata
7
+ # ForeignKeyColumn contains meta-data about columns within a ForeignKey.
8
+ # The attributes are database engine specific.
9
+ # Only column_name and column_id are required by Ramen.
10
+ # See RowDataGateway for more information.
11
+ #
12
+ # Reference Attributes:
13
+ # [column] the foreign key column in the table.
14
+ # [referenced_column] the column in the foreign table.
15
+ #
16
+ # See Database for a description of how ForeignKeyColumn fits in the Ramen collection
17
+ # hierarchy.
18
+ #
19
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-foreign_key_column_rb.html]
20
+ #
21
+ class ForeignKeyColumn < Ramen::RowDataGateway
22
+ attr_reader :column, :referenced_column
23
+
24
+ # :section: External Methods
25
+ # The following methods are intended for use by Ramen's clients.
26
+
27
+ # Comparison, returns -1,0,+1, compares column_name
28
+ def <=> other
29
+ Ramen::RowDataGateway.compare( column_name, other )
30
+ end
31
+
32
+ # :section: Internal Methods
33
+ # The following methods are for Ramen's internal use. They
34
+ # are not intended for clients of Ramen to use.
35
+
36
+ def initialize( record, database )
37
+ super( record, database )
38
+ @column = database.schema[ self.table_schema ].table[ self.table_name ].column[ self.column_name ]
39
+ @referenced_column = database.schema[ self.referenced_table_schema ].table[ self.referenced_table_name ].column[ self.referenced_column_name ]
40
+ end
41
+
42
+ # add_to( database )
43
+ #
44
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
45
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
46
+ def add_to( database )
47
+ database.schema[ self.table_schema ].table[ self.table_name ].
48
+ fk[ self.foreign_key_name ].add_column( self )
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,71 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+ module Ramen::Metadata
6
+
7
+ # Index contains meta-data about indexes within a Table.
8
+ # The attributes are database engine specific.
9
+ # Only index_name and index_id are required by Ramen.
10
+ # See RowDataGateway for more information.
11
+ #
12
+ # Index also contains a collection of IndexColumn objects. These
13
+ # are accessable by the column attribute.
14
+ #
15
+ # See Database for a description of how Index fits in the Ramen collection
16
+ # hierarchy.
17
+ #
18
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-index_rb.html]
19
+ #
20
+ class Index < Ramen::RowDataGateway
21
+ # :section: External Methods
22
+ # The following methods are intended for use by Ramen's clients.
23
+
24
+ # Comparison, returns -1,0,+1, compares index_name
25
+ def <=> other
26
+ Ramen::RowDataGateway.compare( index_name, other )
27
+ end
28
+
29
+ # column() #=> RamenHash reference
30
+ #
31
+ # This attribute provides access to a RamenHash of all IndexColumn objects
32
+ # in the Index. The hash is indexed by column_id and column_name.
33
+ #
34
+ # usage:
35
+ # require 'lib/ramen'
36
+ # db = Ramen.create( configuration )
37
+ # schema = db.schema['HumanResources']
38
+ # table = schema.table['Employee']
39
+ # index = table.index['IX_Employee_ManagerID']
40
+ # index_column = index.column['ManagerID'] #=> #<Ramen::IndexColumn ...
41
+ #
42
+ def column
43
+ @columns
44
+ end
45
+
46
+ # :section: Internal Methods
47
+ # The following methods are for Ramen's internal use. They
48
+ # are not intended for clients of Ramen to use.
49
+
50
+ def initialize( record, database )
51
+ super( record, database )
52
+ @columns = Ramen::RamenHash.new( IndexColumn, 'column' )
53
+ end
54
+
55
+ # add_to( database )
56
+ #
57
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
58
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
59
+ def add_to( database )
60
+ database.schema[ self.table_schema ].table[ self.table_name ].add_index( self )
61
+ end
62
+
63
+ # add_column( obj ) #=> obj
64
+ #
65
+ # Adds the column to this table. Throws a RamenError if the obj
66
+ # is not a IndexColumn.
67
+ def add_column( obj )
68
+ @columns.add( obj )
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+
6
+ module Ramen::Metadata
7
+ # IndexColumn contains meta-data about columns within an Index.
8
+ # The attributes are database engine specific.
9
+ # Only column_name and column_id are required by Ramen.
10
+ # See RowDataGateway for more information.
11
+ #
12
+ # Reference Attributes:
13
+ # [column] the column in the Index.
14
+ #
15
+ # See Database for a description of how IndexColumn fits in the Ramen collection
16
+ # hierarchy.
17
+ #
18
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-index_column_rb.html]
19
+ #
20
+ class IndexColumn < Ramen::RowDataGateway
21
+ attr_reader :column
22
+
23
+ # :section: External Methods
24
+ # The following methods are intended for use by Ramen's clients.
25
+
26
+ # Comparison, returns -1,0,+1, compares column_name
27
+ def <=> other
28
+ Ramen::RowDataGateway.compare( column_name, other )
29
+ end
30
+
31
+ # :section: Internal Methods
32
+ # The following methods are for Ramen's internal use. They
33
+ # are not intended for clients of Ramen to use.
34
+
35
+ def initialize( record, database )
36
+ super( record, database )
37
+ @column = database.schema[ self.table_schema ].table[ self.table_name ].column[ column_name ]
38
+ end
39
+
40
+ # add_to( database )
41
+ #
42
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
43
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
44
+ def add_to( database )
45
+ database.schema[ self.table_schema ].table[ self.table_name ].
46
+ index[ self.index_name ].add_column( self )
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,56 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+ module Ramen::Metadata
6
+
7
+ # (KeyConstraint is left over from an earlier implementation of Ramen that
8
+ # was only concerned with Sql Server 2005. For now, the class has been
9
+ # stripped of features (code commented out). In the future, this will
10
+ # probably get transformed into a UniqueConstraint or simply Constraint class
11
+ # which is better suited for multiple database.)
12
+ #
13
+ # KeyConstraint contains meta-data about key constraints within a Table.
14
+ # The attributes are database engine specific.
15
+ # Only key_constraint_name and key_constraint_id are required by Ramen.
16
+ # See RowDataGateway for more information.
17
+ #
18
+ # Reference Attributes:
19
+ # [index] the index used by the key constraint.
20
+ #
21
+ # See Database for a description of how ForeignKey fits in the Ramen collection
22
+ # hierarchy.
23
+ #
24
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-key_constraint_rb.html]
25
+ #
26
+ class KeyConstraint < Ramen::RowDataGateway
27
+ =begin
28
+ attr_reader :index
29
+
30
+ # :section: External Methods
31
+ # The following methods are intended for use by Ramen's clients.
32
+
33
+ # Comparison, returns -1,0,+1, compares key_name
34
+ def <=> other
35
+ Ramen::RowDataGateway.compare( key_name, other )
36
+ end
37
+
38
+ # :section: Internal Methods
39
+ # The following methods are for Ramen's internal use. They
40
+ # are not intended for clients of Ramen to use.
41
+
42
+ def initialize( record, database )
43
+ super( record, database )
44
+ @index = database.schema[ self.table_schema ].table[ self.table_name ].index[ self.index_name ]
45
+ end
46
+
47
+ # add_to( database )
48
+ #
49
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
50
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
51
+ def add_to( database )
52
+ database.schema[ self.table_schema ].table[ self.table_name ].add_key_constraint( self )
53
+ end
54
+ =end
55
+ end
56
+ end
@@ -0,0 +1,10 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+
6
+ module Ramen
7
+ # TODO document
8
+ module Metadata
9
+ end
10
+ end
@@ -0,0 +1,71 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+ module Ramen::Metadata
6
+
7
+ # PrimaryKey contains meta-data about the primary key for a Table.
8
+ # The attributes are database engine specific.
9
+ # Only primary_key_name is required by Ramen.
10
+ # See RowDataGateway for more information.
11
+ #
12
+ # PrimaryKey also contains a collection of PrimaryKeyColumn objects. These
13
+ # are accessable by the column attribute.
14
+ #
15
+ # See Database for a description of how PrimaryKey fits in the Ramen collection
16
+ # hierarchy.
17
+ #
18
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-primary_key_rb.html]
19
+ #
20
+ class PrimaryKey < Ramen::RowDataGateway
21
+ # :section: External Methods
22
+ # The following methods are intended for use by Ramen's clients.
23
+
24
+ # Comparison, returns -1,0,+1, compares primary_key_name
25
+ def <=> other
26
+ Ramen::RowDataGateway.compare( primary_key_name, other )
27
+ end
28
+
29
+ # column() #=> RamenHash reference
30
+ #
31
+ # This attribute provides access to a RamenHash of all PrimaryKeyColumn objects
32
+ # in the PrimaryKey. The hash is indexed by column_name and column_id (if available).
33
+ #
34
+ # usage:
35
+ # require 'lib/ramen'
36
+ # db = Ramen.create( configuration )
37
+ # schema = db.schema['HumanResources']
38
+ # table = schema.table['Employee']
39
+ # pk = table.pk['PK_Employee_EmployeeID']
40
+ # pk_column = pk.column['EmployeeID'] #=> #<Ramen::PrimaryKeyColumn ...
41
+ #
42
+ def column
43
+ @columns
44
+ end
45
+
46
+ # :section: Internal Methods
47
+ # The following methods are for Ramen's internal use. They
48
+ # are not intended for clients of Ramen to use.
49
+
50
+ def initialize( record, database )
51
+ super( record, database )
52
+ @columns = Ramen::RamenHash.new( PrimaryKeyColumn, 'column' )
53
+ end
54
+
55
+ # add_to( database )
56
+ #
57
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
58
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
59
+ def add_to( database )
60
+ database.schema[ self.table_schema ].table[ self.table_name ].set_primary_key( self )
61
+ end
62
+
63
+ # add_column( obj ) #=> obj
64
+ #
65
+ # Adds the column to this table. Throws a RamenError if the obj
66
+ # is not a ForeignKeyColumn.
67
+ def add_column( obj )
68
+ @columns.add( obj )
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+
6
+ module Ramen::Metadata
7
+ # PrimaryKeyColumn contains meta-data about columns within a PrimaryKey.
8
+ # The attributes are database engine specific.
9
+ # Only column_name and column_id are required by Ramen.
10
+ # See RowDataGateway for more information.
11
+ #
12
+ # Reference Attributes:
13
+ # [column] the primary key column in the table.
14
+ #
15
+ # See Database for a description of how PrimaryKeyColumn fits in the Ramen
16
+ # collection hierarchy.
17
+ #
18
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-primary_key_column_rb.html]
19
+ #
20
+ class PrimaryKeyColumn < Ramen::RowDataGateway
21
+ attr_reader :column
22
+
23
+ # :section: External Methods
24
+ # The following methods are intended for use by Ramen's clients.
25
+
26
+ # Comparison, returns -1,0,+1, compares column_name
27
+ def <=> other
28
+ Ramen::RowDataGateway.compare( column_name, other )
29
+ end
30
+
31
+ # :section: Internal Methods
32
+ # The following methods are for Ramen's internal use. They
33
+ # are not intended for clients of Ramen to use.
34
+
35
+ def initialize( record, database )
36
+ super( record, database )
37
+ @column = database.schema[ self.table_schema ].table[ self.table_name ].column[ self.column_name ]
38
+ end
39
+
40
+ # add_to( database )
41
+ #
42
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
43
+ # (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
44
+ def add_to( database )
45
+ database.schema[ self.table_schema ].table[ self.table_name ].
46
+ pk.add_column( self )
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,86 @@
1
+ #--
2
+ # Copyright (c) 2007 Gregory N. Houston
3
+ # See ramen.rb for license information.
4
+ #++
5
+ module Ramen::Metadata
6
+
7
+ # Schema contains a collection of Tables. Attributes available for Schema
8
+ # are database engine specific. Ramen only requires the attributes
9
+ # schema_name and schema_id. See RowDataGateway for more information.
10
+ #
11
+ # See Database for a description of how Schema fits in the Ramen collection
12
+ # hierarchy.
13
+ #
14
+ # Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-schema_rb.html]
15
+ #
16
+ class Schema < Ramen::RowDataGateway
17
+ # :section: External Methods
18
+ # The following methods are intended for use by Ramen's clients.
19
+
20
+ # Comparison, returns -1,0,+1, compares schema_name
21
+ def <=> other
22
+ Ramen::RowDataGateway.compare( schema_name, other )
23
+ end
24
+
25
+ # table() #=> RamenHash reference
26
+ #
27
+ # This attribute provides access to a RamenHash of all Table objects in the
28
+ # Schema. The hash is indexed by table_name and table_id.
29
+ #
30
+ # usage:
31
+ # require 'lib/ramen'
32
+ # db = Ramen.create( configuration )
33
+ # schema = db.schema['Sales'] #=> #<Schema schema_name='Sales', schema_id='1234567' ...>
34
+ # table = schema.table['Products'] #=> #<Table table_name='Products', table_id='1111111111'>
35
+ # table = schema.table[1111111111] #=> #<Table table_name='Products', table_id='1111111111'>
36
+ #
37
+ def table
38
+ @tables
39
+ end
40
+
41
+ # inspect() #=> string
42
+ #
43
+ # Returns a nice and brief output of the schema and it's tables. This
44
+ # was redefined since the default inspect would typically output many
45
+ # pages of details.
46
+ #
47
+ # Each table is listed by id:name.
48
+ #
49
+ # usage:
50
+ # db = Ramen.create()
51
+ # schema = db.schema['Sales']
52
+ # schema.inspect #=> "#<Ramen::Schema:0x2da0669 table=[1:Promotions, 2:Orders,..."
53
+ #
54
+ def inspect
55
+ children = []
56
+ @tables.each_by_id do |id,table|
57
+ children << (id.to_s+':'+table.table_name)
58
+ end
59
+ to_s[0..-2]+' schema_name=\''+ schema_name+ '\'' + ((self.respond_to?:schema_id)?' schema_id=' + schema_id.to_s : '') + ' tables=['+children.join(', ')+']>'
60
+ end
61
+
62
+ # :section: Internal Methods
63
+ # The following methods are for Ramen's internal use. They
64
+ # are not intended for clients of Ramen to use.
65
+
66
+ def initialize( record, database )
67
+ super(record, database)
68
+ @tables = Ramen::RamenHash.new( Table )
69
+ end
70
+
71
+ # add_to( database )
72
+ #
73
+ # Add self to the given database. (Choosing Message; Double Dispatch pattern)
74
+ def add_to( database )
75
+ database.add_schema( self )
76
+ end
77
+
78
+ # add_table( obj ) #=> obj
79
+ #
80
+ # Adds the given table to this schema. Throws a RamenError if the obj
81
+ # is not a Table.
82
+ def add_table( table )
83
+ @tables.add( table )
84
+ end
85
+ end
86
+ end