Module: NoDB

Overview

Generic_Table

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_TYPE =

NoDB.new(value_array, name_array, type_array) -specified values, names, and types NoDB.new(value_array, type_array) - values with default names and specified types (arrayish) NoDB.new(value_array) - values with default names and types NoDB.new(value_name_hash, type_array) -specified values (Hash.values), names (Hash.keys) and types NoDB.new(value_name_hash)-specified values (Hash.values), names (Hash.keys), and types NoDB.new - empty object no attributes, no values, no names, no types. All can be added.

String

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generic_Table::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 Generic_Table

activeRecordTableNotCreatedYet?, classDefiniton, classReference, class_of_name, eval_constant, is_ActiveRecord_table?, is_generic_table?, is_generic_table_name?, is_table?, rails_MVC_class?, rubyClassName, table_exists?

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes


412
413
414
# File 'app/models/no_db.rb', line 412

def attributes
  @attributes
end

Instance Method Details

#[](attribute_name) ⇒ Object

NoDB initialize


484
485
486
# File 'app/models/no_db.rb', line 484

def [](attribute_name)
	@attributes[attribute_name.to_sym]
end

#[]=(attribute_name, value) ⇒ Object


487
488
489
# File 'app/models/no_db.rb', line 487

def []=(attribute_name, value)
	@attributes[attribute_name.to_sym]=value
end

#cloneObject

table_name


502
503
504
# File 'app/models/no_db.rb', line 502

def clone
	return self.new(@attributes.clone, @types.clone)
end

#each_pair(&block) ⇒ Object

clone


505
506
507
508
509
# File 'app/models/no_db.rb', line 505

def each_pair(&block)
	@attributes.each_pair do |key, value|
		block.call(key, value)
	end #each_pair
end

#has_key?(key_name) ⇒ Boolean

[]=

Returns:

  • (Boolean)

490
491
492
# File 'app/models/no_db.rb', line 490

def has_key?(key_name)
	return @attributes.has_key?(key_name.to_sym)
end

#initialize(values = nil, names = nil, types = nil) ⇒ Object


461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'app/models/no_db.rb', line 461

def initialize(values=nil, names=nil, types=nil)
	if values.nil? then
		@attributes=Hash.new
		@types={}
	elsif values.instance_of?(Array) then
		if names.instance_of?(Array) then
			if !names.all?{|n| n.instance_of?(String)|n.instance_of?(Symbol)} then
				names=self.class.default_names(values)
			end #if
		else #missing names
			names=self.class.default_names(values)
		end #if
		@attributes=Hash[[names, values].transpose]
		@types=types || names
	elsif values.instance_of?(Hash) then
		@attributes=values
		@types=types || names
	else
		message="values=#{values.inspect}, \nnames=#{names.inspect}, \ntypes=#{types.inspect}"
		message+="values.nil?=#{values.nil?.inspect}, \nvalues.instance_of?(Array)=#{values.instance_of?(Array).inspect}, \nvalues.instance_of?(Hash)=#{values.instance_of?(Hash).inspect}"
		raise "confused about arguments to NoDB.initialize.\n"+message
	end #if
end

#insert_sqlObject

each_pair


510
511
512
513
514
515
516
517
518
519
520
521
# File 'app/models/no_db.rb', line 510

def insert_sql
	value_strings=@attributes.values.map do |value|
		if value.nil? then
			"NULL"
		elsif value.instance_of?(String) then
			value.inspect
		else
			value
		end #if
	end #map
	return "INSERT INTO #{self.table_name}(#{self.class.get_field_names.join(',')}) VALUES(#{value_strings.join(',')});\n"
end

#keysObject

has_key?


493
494
495
# File 'app/models/no_db.rb', line 493

def keys
	return @attributes.keys
end

#table_classObject

keys


496
497
498
# File 'app/models/no_db.rb', line 496

def table_class
	return self.class
end

#table_nameObject

table_class


499
500
501
# File 'app/models/no_db.rb', line 499

def table_name
	return table_class.table_name
end