module ChefFixie::Sql::Relationships
Maps entity names like ‘org’ to the table class (Orgs
) and the entity class (Org
), as well as the cannonical each table has a name, a class to wrap the table, an row, and a class to map the row. Wrapping this in a class to handle things if we have to not be consisitent with our naming. table :orgs, class wrapper Orgs
, row :org, class for row Org
Public Class Methods
base()
click to toggle source
# File lib/chef_fixie/sql_objects.rb, line 38 def self.base "ChefFixie::Sql" + "::" # this should be autogenerated not hardcoded end
object_class(name)
click to toggle source
The class for one instance of the object, e.g. Org
# File lib/chef_fixie/sql_objects.rb, line 64 def self.object_class(name) name = to_name(name) (base + name.to_s.singularize.camelize).constantize end
plural(name)
click to toggle source
# File lib/chef_fixie/sql_objects.rb, line 74 def self.plural(name) name = to_name(name) name.to_s.pluralize end
singular(name)
click to toggle source
# File lib/chef_fixie/sql_objects.rb, line 69 def self.singular(name) name = to_name(name) name.to_s.singularize end
table_class(name)
click to toggle source
The class for the table, e.g. Orgs
# File lib/chef_fixie/sql_objects.rb, line 58 def self.table_class(name) name = to_name(name) (base + name.to_s.pluralize.camelize).constantize end
to_name(class_or_name)
click to toggle source
# File lib/chef_fixie/sql_objects.rb, line 42 def self.to_name(class_or_name) name = case when class_or_name.is_a?(Symbol) class_or_name.to_s when class_or_name.is_a?(Class) class_or_name.name when class_or_name.is_a?(String) class_or_name else class_or_name.class.to_s end name.split("::")[-1] end