Module: Generic_Table

Overview

require 'test/assertions/generic_table_assertions.rb' # in test_helper? Methods in common bettween ActiveRecord::Base and NoDB

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from ColumnGroup::ClassMethods

ColumnGroup::ClassMethods::History_columns

Constants included from GenericGrep::ClassMethods

GenericGrep::ClassMethods::ASSOCIATION_MACRO_LETTERS, GenericGrep::ClassMethods::ASSOCIATION_MACRO_PATTERN

Constants included from GenericTableAssociation::Examples

GenericTableAssociation::Examples::First_stream_method

Class Method Summary collapse

Methods included from ClassMethods

is_active_record_method?, model_file_name, nesting, one_pass_statistics, sample, sample_burst

Methods included from ColumnGroup::ClassMethods

#attribute_ddl, #attribute_rails_type, #attribute_ruby_type, #candidate_logical_keys_from_indexes, #categorical?, #column_symbols, #default_logical_primary_key, #defaulted_primary_logical_key?, #history_type?, #is_logical_primary_key?, #logical_attributes, #logical_primary_key, #logical_primary_key_recursive, #numerical?, #probably_categorical?, #probably_numerical?, #sequential_id?

Methods included from GenericGrep::ClassMethods

#all_associations, #association_grep, #association_grep_pattern, #association_macro_type, #association_type, #belongs_to_association?, #grep_all_associations_command, #grep_command, #has_many_association?, #has_one_association?, #model_grep, #model_grep_command

Methods included from GenericTableHtml::ClassMethods

#column_order, #header_html, #table_html

Methods included from GenericTableAssociation

#associated_foreign_key_records, #associated_to_s, #association_class, #association_has_data, #association_state, #foreign_key_points_to_me?, #foreign_key_to_association, #foreign_key_value, #logical_primary_key_recursive_value, #logical_primary_key_value, #name_to_association

Methods included from GenericTableAssociation::Assertions::ClassMethods

#assert_foreign_keys_not_nil, #assert_invariant, #assert_post_conditions, #assert_pre_conditions

Methods included from GenericTableAssociation::Assertions

#assert_associated_foreign_key, #assert_associated_foreign_key_name, #assert_association, #assert_association_methods, #assert_association_to_many, #assert_association_to_one, #assert_foreign_key_association_names, #assert_foreign_key_name, #assert_foreign_key_not_nil, #assert_foreign_keys_not_nil, #assert_invariant, #assert_post_conditions, #assert_pre_conditions

Methods included from GenericTableHtml

#column_html, #rails_route, #row_html

Class Method Details

.activeRecordTableNotCreatedYet?(obj) ⇒ Boolean

Returns:

  • (Boolean)

194
195
196
# File 'app/models/generic_table.rb', line 194

def Generic_Table.activeRecordTableNotCreatedYet?(obj)
	return (obj.class.inspect=~/^[a-zA-Z0-9_]+\(Table doesn\'t exist\)/)==0
end

.class_of_name(name) ⇒ Object

gone_manual! require 'app/models/IncludeModuleClassMethods.rb'


164
165
166
167
168
# File 'app/models/generic_table.rb', line 164

def Generic_Table.class_of_name(name)
	 return name.to_s.constantize
rescue
	return nil
end

.classDefiniton(model_class_name) ⇒ Object

def


417
418
419
# File 'app/models/generic_table.rb', line 417

def Generic_Table.classDefiniton(model_class_name)
	return "class #{Generic_Table.rubyClassName(model_class_name)}  < ActiveRecord::Base\ninclude Generic_Table\nend"
end

.classReference(model_class_name) ⇒ Object

def


420
421
422
423
424
# File 'app/models/generic_table.rb', line 420

def Generic_Table.classReference(model_class_name)
	rubyClassName=Generic_Table.rubyClassName(model_class_name)
	model_class_eval=eval("#{classDefiniton(rubyClassName)}\n#{rubyClassName}")
	return model_class_eval
end

.eval_constant(constant_name) ⇒ Object

Match_and_strip


463
464
465
466
467
# File 'app/models/generic_table.rb', line 463

def Generic_Table.eval_constant(constant_name)
	constant_name.constantize
rescue NameError
	return nil
end

.is_ActiveRecord_table?(model_class_name) ⇒ Boolean

def

Returns:

  • (Boolean)

478
479
480
481
482
483
484
485
# File 'app/models/generic_table.rb', line 478

def Generic_Table.is_ActiveRecord_table?(model_class_name)
	if Generic_Table.is_table?(model_class_name.tableize) then
		model_class=Generic_Table.eval_constant(model_class_name.classify)
		model_class.new.kind_of?(ActiveRecord::Base)
	else
		return false
	end #if
end

.is_generic_table?(model_class_name) ⇒ Boolean

class_of_name

Returns:

  • (Boolean)

169
170
171
172
173
174
175
176
177
# File 'app/models/generic_table.rb', line 169

def Generic_Table.is_generic_table?(model_class_name)
	return false if (model_class_name =~ /_ids$/)
	if Generic_Table.is_ActiveRecord_table?(model_class_name) then
		model_class=Generic_Table.eval_constant(model_class_name.classify)
		model_class.module_included?(Generic_Table)
	else
		return false
	end #if
end

.is_generic_table_name?(model_file_basename, directory = 'app/models/', extention = '.rb') ⇒ Boolean

rails_MVC_class

Returns:

  • (Boolean)

184
185
186
187
188
189
190
191
# File 'app/models/generic_table.rb', line 184

def Generic_Table.is_generic_table_name?(model_file_basename,directory='app/models/',extention='.rb')
	if File.exists?(directory+model_file_basename+extention) then
		return true
	else
#		puts "File.exists?(\"#{directory+model_file_basename+extention})\")=#{File.exists?(directory+model_file_basename+extention)}"
		return false
	end #if
end

.is_table?(table_name) ⇒ Boolean

def

Returns:

  • (Boolean)

468
469
470
471
472
473
474
475
476
477
# File 'app/models/generic_table.rb', line 468

def Generic_Table.is_table?(table_name)
	raise "table_name must include only [A-Za-z0-9_]." if (table_name =~ /^[A-Za-z0-9_]+$/).nil?
	if Generic_Table.table_exists?(table_name) then
		return true
	#~ elsif Generic_Table.table_exists?(table_name.tableize) then
		#~ return true
	else
		return false
	end #if
end

.rails_MVC_class?(table_name) ⇒ Boolean

table_exists

Returns:

  • (Boolean)

181
182
183
# File 'app/models/generic_table.rb', line 181

def Generic_Table.rails_MVC_class?(table_name)
	return CodeBase.rails_MVC_classes.map{|c| c.name}.include?(table_name.to_s.classify)
end

.rubyClassName(model_class_name) ⇒ Object


412
413
414
415
416
# File 'app/models/generic_table.rb', line 412

def Generic_Table.rubyClassName(model_class_name)
	model_class_name=model_class_name[0,1].upcase+model_class_name[1,model_class_name.length-1] # ruby class names are constants and must start with a capital letter.
	# remainng case is unchanged to allow camel casing to separate words for model names.
	return model_class_name
end

.table_exists?(table_name) ⇒ Boolean

def

Returns:

  • (Boolean)

178
179
180
# File 'app/models/generic_table.rb', line 178

def Generic_Table.table_exists?(table_name)
	TableSpec.connection.table_exists?(table_name)
end