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.
- data/doc/doc_resources/MetaData_Class_Diagram.gif +0 -0
- data/doc/doc_resources/MetaData_Class_Diagram.png +0 -0
- data/doc/doc_resources/Thumbs.db +0 -0
- data/lib/ramen/core.rb +75 -0
- data/lib/ramen/default_logger.rb +29 -0
- data/lib/ramen/engine/engine.rb +34 -0
- data/lib/ramen/engine/mysql.rb +225 -0
- data/lib/ramen/engine/sql2005.rb +377 -0
- data/lib/ramen/home.rb +162 -0
- data/lib/ramen/metadata/column.rb +38 -0
- data/lib/ramen/metadata/database.rb +137 -0
- data/lib/ramen/metadata/foreign_key.rb +71 -0
- data/lib/ramen/metadata/foreign_key_column.rb +51 -0
- data/lib/ramen/metadata/index.rb +71 -0
- data/lib/ramen/metadata/index_column.rb +49 -0
- data/lib/ramen/metadata/key_constraint.rb +56 -0
- data/lib/ramen/metadata/metadata.rb +10 -0
- data/lib/ramen/metadata/primary_key.rb +71 -0
- data/lib/ramen/metadata/primary_key_column.rb +49 -0
- data/lib/ramen/metadata/schema.rb +86 -0
- data/lib/ramen/metadata/table.rb +202 -0
- data/lib/ramen/ramen_error.rb +16 -0
- data/lib/ramen/ramen_hash.rb +143 -0
- data/lib/ramen/ramen_module.rb +52 -0
- data/lib/ramen/row_data_gateway.rb +89 -0
- data/lib/ramen/version.rb +16 -0
- data/lib/ramen.rb +62 -0
- data/readme.txt +159 -0
- data/test/config/config.yml +19 -0
- data/test/helper.rb +18 -0
- data/test/mysql_create_test_db.sql +47 -0
- data/test/sql2005_create_test_db.sql +45 -0
- data/test/test_bugs.rb +32 -0
- data/test/test_core.rb +63 -0
- data/test/test_default_logger.rb +38 -0
- data/test/test_home.rb +33 -0
- data/test/test_ramen.rb +274 -0
- data/test/test_ramen_hash.rb +78 -0
- data/test/test_ramen_module.rb +21 -0
- metadata +99 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
|
|
6
|
+
module Ramen::Metadata
|
|
7
|
+
# Table contains collections of Column, ForeignKey, Index, KeyConstraint, and
|
|
8
|
+
# PrimaryKey objects. Attributes available for Table are database engine specific.
|
|
9
|
+
# Ramen only requires the attributes table_name and table_id. See
|
|
10
|
+
# RowDataGateway for more information.
|
|
11
|
+
#
|
|
12
|
+
# See Database for a description of how Table fits in the Ramen collection
|
|
13
|
+
# hierarchy.
|
|
14
|
+
#
|
|
15
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-table_rb.html]
|
|
16
|
+
#
|
|
17
|
+
class Table < Ramen::RowDataGateway
|
|
18
|
+
# :section: External Methods
|
|
19
|
+
# The following methods are intended for use by Ramen's clients.
|
|
20
|
+
|
|
21
|
+
# Comparison, returns -1,0,+1, compares table_name
|
|
22
|
+
def <=> other
|
|
23
|
+
Ramen::RowDataGateway.compare( table_name, other )
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# column() #=> RamenHash reference
|
|
27
|
+
#
|
|
28
|
+
# This attribute provides access to a RamenHash of all Column objects in the
|
|
29
|
+
# Table. The hash is indexed by column_name and column_id.
|
|
30
|
+
#
|
|
31
|
+
# usage:
|
|
32
|
+
# require 'lib/ramen'
|
|
33
|
+
# db = Ramen.create( configuration )
|
|
34
|
+
# schema = db.schema['Sales'] #=> #<Schema schema_name='Sales', schema_id='1234567' ...>
|
|
35
|
+
# table = schema.table['Products'] #=> #<Table table_name='Products', table_id='1111111111'>
|
|
36
|
+
# column = table.column['Price'] #=> #<Column...>
|
|
37
|
+
#
|
|
38
|
+
def column
|
|
39
|
+
@columns
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# foreign_key() #=> RamenHash reference
|
|
43
|
+
#
|
|
44
|
+
# fk() #=> RamenHash reference
|
|
45
|
+
#
|
|
46
|
+
# This attribute provides access to a RamenHash of all ForeignKey objects
|
|
47
|
+
# in the Table. The hash is indexed by foreign_key_id and foreign_key_name.
|
|
48
|
+
#
|
|
49
|
+
# usage:
|
|
50
|
+
# require 'lib/ramen'
|
|
51
|
+
# db = Ramen.create( configuration )
|
|
52
|
+
# schema = db.schema['Sales']
|
|
53
|
+
# table = schema.table['Products']
|
|
54
|
+
# fk = table.fk['FK_PRODUCTS_ORDERS'] #=> #<ForeignKey...>
|
|
55
|
+
#
|
|
56
|
+
def foreign_key
|
|
57
|
+
@foreign_keys
|
|
58
|
+
end
|
|
59
|
+
alias fk foreign_key
|
|
60
|
+
|
|
61
|
+
# index() #=> RamenHash reference
|
|
62
|
+
#
|
|
63
|
+
# This attribute provides access to a RamenHash of all Index objects
|
|
64
|
+
# in the Table. The hash is indexed by index_id and index_name.
|
|
65
|
+
#
|
|
66
|
+
# usage:
|
|
67
|
+
# require 'lib/ramen'
|
|
68
|
+
# db = Ramen.create( configuration )
|
|
69
|
+
# schema = db.schema['Sales']
|
|
70
|
+
# table = schema.table['Products']
|
|
71
|
+
# index = table.index['PK_PRODUCTS_ID'] #=> #<Index...>
|
|
72
|
+
#
|
|
73
|
+
def index
|
|
74
|
+
@indexes
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# key_constraint() #=> RamenHash reference
|
|
78
|
+
#
|
|
79
|
+
# key () #=> RamenHash reference
|
|
80
|
+
#
|
|
81
|
+
# This attribute provides access to a RamenHash of all KeyConstraint objects
|
|
82
|
+
# in the Table. The hash is indexed by key_constraint_id and
|
|
83
|
+
# key_constraint_name.
|
|
84
|
+
#
|
|
85
|
+
# usage:
|
|
86
|
+
# require 'lib/ramen'
|
|
87
|
+
# db = Ramen.create( configuration )
|
|
88
|
+
# schema = db.schema['Sales']
|
|
89
|
+
# table = schema.table['Products']
|
|
90
|
+
# key_constraint = table.key['UK_PRODUCTS_NAME'] #=> #<KeyConstraint...>
|
|
91
|
+
#
|
|
92
|
+
=begin
|
|
93
|
+
def key_constraint
|
|
94
|
+
@key_constraints
|
|
95
|
+
end
|
|
96
|
+
alias key key_constraint
|
|
97
|
+
=end
|
|
98
|
+
|
|
99
|
+
# primary_key() #=> PrimaryKey reference
|
|
100
|
+
#
|
|
101
|
+
# pk() #=> PrimaryKey reference
|
|
102
|
+
#
|
|
103
|
+
# This attribute provides access to a RamenHash of all ForeignKey objects
|
|
104
|
+
# in the Table. The hash is indexed by foreign_key_id and foreign_key_name.
|
|
105
|
+
#
|
|
106
|
+
# usage:
|
|
107
|
+
# require 'lib/ramen'
|
|
108
|
+
# db = Ramen.create( configuration )
|
|
109
|
+
# schema = db.schema['Sales']
|
|
110
|
+
# table = schema.table['Products']
|
|
111
|
+
# fk = table.fk['PK_PRODUCTS'] #=> #<PrimaryKey...>
|
|
112
|
+
#
|
|
113
|
+
def primary_key
|
|
114
|
+
@primary_key
|
|
115
|
+
end
|
|
116
|
+
alias pk primary_key
|
|
117
|
+
|
|
118
|
+
# inspect() #=> string
|
|
119
|
+
#
|
|
120
|
+
# Returns a nice and brief output of the table and it's tables. This
|
|
121
|
+
# was redefined since the default inspect would typically output many
|
|
122
|
+
# pages of details.
|
|
123
|
+
#
|
|
124
|
+
# Each table is listed by id:name.
|
|
125
|
+
#
|
|
126
|
+
# usage:
|
|
127
|
+
# db = Ramen.create()
|
|
128
|
+
# schema = db.schema['HumanResources']
|
|
129
|
+
# table = schema.table['Employee']
|
|
130
|
+
# table.inspect #=> "#<Ramen::Table columns=[1:EmployeeID, 2:NationalIDNumber, ..."
|
|
131
|
+
#
|
|
132
|
+
def inspect
|
|
133
|
+
children = []
|
|
134
|
+
@columns.each_by_id do |id,col|
|
|
135
|
+
children << (id.to_s+':'+col.column_name)
|
|
136
|
+
end
|
|
137
|
+
to_s[0..-2]+' '+table_name+' columns=['+children.join(', ')+']>'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# :section: Internal Methods
|
|
141
|
+
# The following methods are for Ramen's internal use. They
|
|
142
|
+
# are not intended for clients of Ramen to use.
|
|
143
|
+
|
|
144
|
+
def initialize( record, database )
|
|
145
|
+
super( record, database )
|
|
146
|
+
@columns = Ramen::RamenHash.new( Column )
|
|
147
|
+
@foreign_keys = Ramen::RamenHash.new( ForeignKey )
|
|
148
|
+
@indexes = Ramen::RamenHash.new( Index )
|
|
149
|
+
@key_constraints = Ramen::RamenHash.new( KeyConstraint, 'key' )
|
|
150
|
+
@primary_key = nil
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# add_to( database )
|
|
154
|
+
#
|
|
155
|
+
# Add self to the given database. (Choosing Message; Double Dispatch pattern)
|
|
156
|
+
# (Kent Beck. Smalltalk Best Practices Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
|
|
157
|
+
def add_to( database )
|
|
158
|
+
database.schema[ self.table_schema ].add_table( self )
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# add_column( obj ) #=> obj
|
|
162
|
+
#
|
|
163
|
+
# Adds the column to this table. Throws a RamenError if the obj
|
|
164
|
+
# is not a Column.
|
|
165
|
+
def add_column( column )
|
|
166
|
+
@columns.add( column )
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# add_foreign_key( obj ) #=> obj
|
|
170
|
+
#
|
|
171
|
+
# Adds the foreign key to this table. Throws a RamenError if the obj
|
|
172
|
+
# is not a ForeignKey.
|
|
173
|
+
def add_foreign_key( fk )
|
|
174
|
+
@foreign_keys.add( fk )
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# add_index( obj ) #=> obj
|
|
178
|
+
#
|
|
179
|
+
# Adds the index to this table. Throws a RamenError if the obj
|
|
180
|
+
# is not a Index.
|
|
181
|
+
def add_index( index )
|
|
182
|
+
@indexes.add( index )
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# add_key_constraint( obj ) #=> obj
|
|
186
|
+
#
|
|
187
|
+
# Adds the key constraint to this table. Throws a RamenError if the obj
|
|
188
|
+
# is not a KeyConstraint.
|
|
189
|
+
=begin
|
|
190
|
+
def add_key_constraint( obj )
|
|
191
|
+
@key_constraints.add( obj )
|
|
192
|
+
end
|
|
193
|
+
=end
|
|
194
|
+
|
|
195
|
+
# set_primary_key( obj ) #=> obj
|
|
196
|
+
#
|
|
197
|
+
# Sets the primary key for this table.
|
|
198
|
+
def set_primary_key( key )
|
|
199
|
+
@primary_key = key
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
|
|
6
|
+
module Ramen
|
|
7
|
+
# A class for all errors originating in Ramen code. Subclass of StandardError.
|
|
8
|
+
# Errors throw by code which Ramen calls (DBI.execute for example) are not
|
|
9
|
+
# wrapped by RamenError, the original error is rethrown. Only errors which
|
|
10
|
+
# Ramen creates are instances of this class.
|
|
11
|
+
#
|
|
12
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-ramen_error_rb.html]
|
|
13
|
+
#
|
|
14
|
+
class RamenError < StandardError
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
module Ramen
|
|
6
|
+
|
|
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
|
|
10
|
+
# RamenHash will collect.
|
|
11
|
+
#
|
|
12
|
+
# usage:
|
|
13
|
+
# def SomeClass
|
|
14
|
+
# attr_accessor :some_class_id, :some_class_name
|
|
15
|
+
# def initialize( id, name )
|
|
16
|
+
# @some_class_id = id
|
|
17
|
+
# @some_class_name = name
|
|
18
|
+
# end
|
|
19
|
+
# end
|
|
20
|
+
# 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'>
|
|
24
|
+
#
|
|
25
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-ramen_hash_rb.html]
|
|
26
|
+
#
|
|
27
|
+
class RamenHash < Hash
|
|
28
|
+
include Enumerable
|
|
29
|
+
|
|
30
|
+
# RamenHash#new(clazz, prefix) #=> ramen_hash
|
|
31
|
+
#
|
|
32
|
+
# Parameters:
|
|
33
|
+
# [clazz] the type which RamenHash will store.
|
|
34
|
+
# [prefix] (optional) the attribute prefix for indexing.
|
|
35
|
+
#
|
|
36
|
+
# RamenHash indexes each obj by *prefix*_id and *prefix*_name. Where
|
|
37
|
+
# prefix defaults to the clazz's name converted by String#to_delimited_words.
|
|
38
|
+
#
|
|
39
|
+
# For example for Ramen.new( ForeignKey ), the hash is indexed by
|
|
40
|
+
# foreign_key_id and foreign_key_name.
|
|
41
|
+
#
|
|
42
|
+
# RamenHash makes []= private since assignment to an index is not allowed.
|
|
43
|
+
# Use add( obj ) instead.
|
|
44
|
+
#
|
|
45
|
+
def initialize( clazz, prefix = nil )
|
|
46
|
+
prefix ||= clazz.name.match( /[^:]*$/ )[0].to_delimited_words
|
|
47
|
+
@clazz = clazz
|
|
48
|
+
@id = "#{prefix}_id".to_sym
|
|
49
|
+
@name = "#{prefix}_name".to_sym
|
|
50
|
+
@ids = []
|
|
51
|
+
@names = [] # TODO Change to SortedArray
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# add( obj ) #=> obj
|
|
55
|
+
#
|
|
56
|
+
# Adds the object to the hash, ensuring it is stored
|
|
57
|
+
# based on name and id attributes.
|
|
58
|
+
#
|
|
59
|
+
# Throws a RamenError if the obj is not an instance of the class which
|
|
60
|
+
# RamenHash is collecting.
|
|
61
|
+
def add( obj )
|
|
62
|
+
unless obj.is_a? @clazz
|
|
63
|
+
raise RamenError, "can not add type to #RamenHash. type_added=#{obj.class}; type_allowed=#{@clazz}"
|
|
64
|
+
end
|
|
65
|
+
|
|
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
|
+
name = obj.send(@name)
|
|
74
|
+
name = name.downcase if name.respond_to?(:downcase)
|
|
75
|
+
@names << name
|
|
76
|
+
@names.sort! # TODO Change to SortedArray
|
|
77
|
+
self[name]=obj
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# calls the block, passing the block objects stored in the hash (in name order)
|
|
81
|
+
#
|
|
82
|
+
def each()
|
|
83
|
+
@names.each do |name|
|
|
84
|
+
yield self[name]
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
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
|
+
def to_s
|
|
120
|
+
results = []
|
|
121
|
+
self.each_by_id do |key, value|
|
|
122
|
+
results << (key.to_s + ':' + self[key].send(@name) + '=>' + value.to_s)
|
|
123
|
+
end
|
|
124
|
+
results.join( ' ' )
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def default( arg )
|
|
128
|
+
raise RamenError, "RamenHash(#{@clazz.name}) does not contain object for key. key=#{arg}. keys=#{keys.inspect}"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def []( key )
|
|
132
|
+
key = key.downcase if key.respond_to?(:downcase)
|
|
133
|
+
super
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def []=( key, value )
|
|
137
|
+
key = key.downcase if key.respond_to?(:downcase)
|
|
138
|
+
super
|
|
139
|
+
end
|
|
140
|
+
private "[]=".to_sym
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
require 'dbi'
|
|
6
|
+
|
|
7
|
+
=begin rdoc
|
|
8
|
+
Ramen module is primarily a namespace containing all library
|
|
9
|
+
classes and modules.
|
|
10
|
+
|
|
11
|
+
Ramen is also useful for creating the Database instance
|
|
12
|
+
|
|
13
|
+
Detailed documentation is available at http://ramen.rubyforge.org
|
|
14
|
+
=end
|
|
15
|
+
module Ramen
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
# Ramen.create( configuration ) #=> new Metadata::Database instance
|
|
19
|
+
#
|
|
20
|
+
# A constructor method which creates a database with the given :connection, :sql
|
|
21
|
+
# and :logger (see Home.new for details about the parameters and defaults).
|
|
22
|
+
#
|
|
23
|
+
# usage:
|
|
24
|
+
#
|
|
25
|
+
# database = Ramen.create( :connection => DBI.connect(...), :sql => Sql2005.new )
|
|
26
|
+
#
|
|
27
|
+
# The configuration hash can include the following options:
|
|
28
|
+
#
|
|
29
|
+
# :connection => connection to use for database access;
|
|
30
|
+
# default = no default, :connection is required
|
|
31
|
+
#
|
|
32
|
+
# :logger => a logger, see DefaultLogger for an example;
|
|
33
|
+
# default = DefaultLogger
|
|
34
|
+
#
|
|
35
|
+
# :sql => class which provides the sql statments;
|
|
36
|
+
# default = Sql2005
|
|
37
|
+
#
|
|
38
|
+
# Ramen does not hold on to the connection. After this method returns, it
|
|
39
|
+
# is safe to close the connection or use it for other queries.
|
|
40
|
+
#
|
|
41
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-ramen_module_rb.html]
|
|
42
|
+
#
|
|
43
|
+
def create( configuration={} )
|
|
44
|
+
connection = configuration[:connection]
|
|
45
|
+
configuration.delete(:connection)
|
|
46
|
+
if connection.nil?
|
|
47
|
+
raise RamenError.new( "Ramen.create called with :connection => nil." )
|
|
48
|
+
end
|
|
49
|
+
Metadata::Database.new(connection, Home.new( configuration ))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
module Ramen
|
|
6
|
+
|
|
7
|
+
# RowDataGateway implements a simple read-only Row Data Gateway pattern (Fow03).
|
|
8
|
+
# It simply creates a ruby attribute for each column in the data set row.
|
|
9
|
+
#
|
|
10
|
+
# RowDataGateway is the parent class for all classes which contain data from
|
|
11
|
+
# the database in Ramen.
|
|
12
|
+
#
|
|
13
|
+
# The attributes are derived from the row. Thus to add or remove an attribute
|
|
14
|
+
# the query would need updating, not the Ruby code.
|
|
15
|
+
#
|
|
16
|
+
# RowDataGateway assumes the attributes will not clash with methods that
|
|
17
|
+
# already exist on Ruby classes. For example, using 'id' or 'name'
|
|
18
|
+
# for columns is a bad idea since Ruby already defines these attributes.
|
|
19
|
+
# The query can rename such columns to something more appropriate (table_name
|
|
20
|
+
# for example).
|
|
21
|
+
#
|
|
22
|
+
# Subclasses:
|
|
23
|
+
#
|
|
24
|
+
# Column, ForeignKey, ForeignKeyColumn, Index, IndexColumn, KeyConstraint,
|
|
25
|
+
# Schema, Table
|
|
26
|
+
#
|
|
27
|
+
# Bibliography:
|
|
28
|
+
#
|
|
29
|
+
# (Fow03) Martin Fowler. Patterns of Enterprise Application Architecture.
|
|
30
|
+
# Addison Wesley Longman, Reading, MA, 2003.
|
|
31
|
+
#
|
|
32
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-row_data_gateway_rb.html]
|
|
33
|
+
#
|
|
34
|
+
class RowDataGateway
|
|
35
|
+
# :section: Internal Methods
|
|
36
|
+
# The following methods are for Ramen's internal use. They
|
|
37
|
+
# are not intended for clients of Ramen to use.
|
|
38
|
+
|
|
39
|
+
class << self
|
|
40
|
+
# add_attributes( name )
|
|
41
|
+
#
|
|
42
|
+
# Creates and maps attributes provided by the Array of column names.
|
|
43
|
+
# This is performed at the class level since all instances of the class
|
|
44
|
+
# in Ramen have the same columns.
|
|
45
|
+
#
|
|
46
|
+
# The name Array should give the name of each column in the same order
|
|
47
|
+
# contained in the row.
|
|
48
|
+
#
|
|
49
|
+
# usage:
|
|
50
|
+
#
|
|
51
|
+
# def MyData < RowDataGateway
|
|
52
|
+
# end
|
|
53
|
+
#
|
|
54
|
+
# MyData.add_attributes( ['one','two','three'] )
|
|
55
|
+
# my_data = MyData.new( [1,2,3], nil )
|
|
56
|
+
# my_data.one #=> 1
|
|
57
|
+
# my_data.two #=> 2
|
|
58
|
+
# my_data.three #=> 3
|
|
59
|
+
#
|
|
60
|
+
def add_attributes( names )
|
|
61
|
+
(0...names.length).each do |index|
|
|
62
|
+
unless self.instance_methods.include? names[index]
|
|
63
|
+
attribute = names[index].downcase.to_sym
|
|
64
|
+
module_eval( "def #{attribute}() @record[#{index}]; end" )
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Comparison, returns -1,0,+1, compares name attribute (schema_name,
|
|
70
|
+
# table_name, index_name, primary_key_name)
|
|
71
|
+
#
|
|
72
|
+
# Common code used by sub
|
|
73
|
+
def compare( name, other )
|
|
74
|
+
return nil if other.nil?
|
|
75
|
+
result = other <=> name
|
|
76
|
+
(result.nil?) ? nil : -result
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# new( record, database ) #=> new RowDataGateway instance
|
|
81
|
+
#
|
|
82
|
+
# Initialize a new instance with the given record. The database parameter
|
|
83
|
+
# is used by subclasses to add the instance to a Database.
|
|
84
|
+
#
|
|
85
|
+
def initialize( record, database )
|
|
86
|
+
@record = record
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
|
|
6
|
+
module Ramen
|
|
7
|
+
#
|
|
8
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-version_rb.html]
|
|
9
|
+
#
|
|
10
|
+
module Version
|
|
11
|
+
MAJOR = 0
|
|
12
|
+
MINOR = 4
|
|
13
|
+
REVISION = 0
|
|
14
|
+
STRING = [MAJOR, MINOR, REVISION].join('.')
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/ramen.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Ramen
|
|
2
|
+
#
|
|
3
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen_rb.html]
|
|
4
|
+
#
|
|
5
|
+
# License:
|
|
6
|
+
#
|
|
7
|
+
# (The MIT License + Free Software Foundation Advertising Prohibition)
|
|
8
|
+
#
|
|
9
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
10
|
+
#
|
|
11
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
# in the Software without restriction, including without limitation the rights
|
|
14
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
# furnished to do so, subject to the following conditions:
|
|
17
|
+
#
|
|
18
|
+
# The above copyright notice and this permission notice shall be included in
|
|
19
|
+
# all copies or substantial portions of the Software.
|
|
20
|
+
#
|
|
21
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
27
|
+
# THE SOFTWARE.
|
|
28
|
+
#
|
|
29
|
+
# Except as contained in this notice, the name(s) of the above copyright holders
|
|
30
|
+
# shall not be used in advertising or otherwise to promote the sale, use or other
|
|
31
|
+
# dealings in this Software without prior written authorization.
|
|
32
|
+
unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
33
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# modules and classes
|
|
37
|
+
require 'ramen/row_data_gateway'# superclass to metadata classes
|
|
38
|
+
|
|
39
|
+
require 'ramen/metadata/metadata'
|
|
40
|
+
require 'ramen/metadata/column'
|
|
41
|
+
require 'ramen/metadata/database'
|
|
42
|
+
require 'ramen/metadata/foreign_key'
|
|
43
|
+
require 'ramen/metadata/foreign_key_column'
|
|
44
|
+
require 'ramen/metadata/index'
|
|
45
|
+
require 'ramen/metadata/index_column'
|
|
46
|
+
require 'ramen/metadata/key_constraint'
|
|
47
|
+
require 'ramen/metadata/primary_key'
|
|
48
|
+
require 'ramen/metadata/primary_key_column'
|
|
49
|
+
require 'ramen/metadata/schema'
|
|
50
|
+
require 'ramen/metadata/table'
|
|
51
|
+
|
|
52
|
+
require 'ramen/engine/engine'
|
|
53
|
+
require 'ramen/engine/sql2005'
|
|
54
|
+
require 'ramen/engine/mysql'
|
|
55
|
+
|
|
56
|
+
require 'ramen/core'
|
|
57
|
+
require 'ramen/default_logger'
|
|
58
|
+
require 'ramen/ramen_error'
|
|
59
|
+
require 'ramen/home'
|
|
60
|
+
require 'ramen/ramen_hash'
|
|
61
|
+
require 'ramen/ramen_module'
|
|
62
|
+
require 'ramen/version'
|