Class: ModelName

Inherits:
Object show all
Includes:
NoDB
Defined in:
app/models/code.rb

Overview

MatchedPathName

Constant Summary

Constants included from NoDB

NoDB::DEFAULT_TYPE

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

Attributes included from NoDB

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NoDB

#[], #[]=, #clone, #each_pair, #has_key?, #insert_sql, #keys, #table_class, #table_name

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

Constructor Details

#initialize(model_name, plurality = nil) ⇒ ModelName

Returns a new instance of ModelName.


347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'app/models/code.rb', line 347

def initialize(model_name, plurality=nil)
	super()
	if model_name.instance_of?(MatchedPathName) then
		plurality=model_name[:spec][:plural]
		model_name=model_name.matched_model_name
	end #if
	case plurality
	when nil
		self[:singular_model_name]=model_name.singularize
		self[:plural_model_name]=model_name.pluralize
	when false
		self[:singular_model_name]=model_name
		self[:plural_model_name]=nil
	when true
		self[:singular_model_name]=nil
		self[:plural_model_name]=model_name
	else
		raise "unexpected value of plurality=#{plurality}"
	end
end

Class Method Details

.allObject

initialize


367
368
369
370
371
372
373
374
375
376
377
378
# File 'app/models/code.rb', line 367

def self.all
	controller_spec=CodeBase.find_by_name(:controllers)
	controller_pathnames=controller_spec.pathnames
	pattern='(\w+)\.all'
	regexp=Regexp.new(pattern)
	delimiter="\n"
	grep_matches=Generic_Table.grep(controller_pathnames, pattern, delimiter).map do |h|
		model_name=ModelName.new(h[:match].tableize, :singular)
		model_name[:plural_model_name]=h[:pathname]
	end #map
	return grep_matches
end

Instance Method Details

#find_model_name(plural) ⇒ Object


395
396
397
398
399
400
401
# File 'app/models/code.rb', line 395

def find_model_name(plural)
	if plural then
		return self[:singular_model_name].pluralize
	else
		return self[:plural_model_name].singularize	
	end #if
end

#grep_controller_scaffold_variables(plural_model_name) ⇒ Object

find_model_name


402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'app/models/code.rb', line 402

def grep_controller_scaffold_variables(plural_model_name)
	pattern='(\w+)\.all'
	controller_spec=CodeBase.find_by_name(:controllers)
	controller_pathnames=controller_spec.pathnames
	pattern='(\w+)\.all'
	regexp=Regexp.new(pattern)
	delimiter="\n"
	grep_matches=Generic_Table.grep(controller_pathnames, regexp, delimiter).map do |h|
		model_name=ModelName.new(h[:match].tableize, :singular)
		model_name[:plural_model_name]=h[:pathname]
	end #map
	return grep_matches
end

#plural_model_nameObject

singular_model_name


386
387
388
389
390
391
392
# File 'app/models/code.rb', line 386

def plural_model_name
	if self[:plural_model_name].nil? then
		return find_model_name(true)
	else
		return self[:plural_model_name]
	end #if
end

#singular_model_nameObject

ModelName_all


379
380
381
382
383
384
385
# File 'app/models/code.rb', line 379

def singular_model_name
	if self[:singular_model_name].nil? then
		return find_model_name(false)
	else
		return self[:singular_model_name]
	end #if
end

#verify_model_name?(model_name, plurality) ⇒ Boolean

plural_model_name

Returns:

  • (Boolean)

393
394
# File 'app/models/code.rb', line 393

def verify_model_name?(model_name, plurality)
end