Module: ChefFixie::Sql::Relationships
- Defined in:
- lib/chef_fixie_shahid/sql_objects.rb
Overview
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
Class Method Summary collapse
- .base ⇒ Object
-
.object_class(name) ⇒ Object
The class for one instance of the object, e.g.
- .plural(name) ⇒ Object
- .singular(name) ⇒ Object
-
.table_class(name) ⇒ Object
The class for the table, e.g.
- .to_name(class_or_name) ⇒ Object
Class Method Details
.base ⇒ Object
38 39 40 |
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 38 def self.base "ChefFixie::Sql" + "::" # this should be autogenerated not hardcoded end |
.object_class(name) ⇒ Object
The class for one instance of the object, e.g. Org
64 65 66 67 |
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 64 def self.object_class(name) name = to_name(name) (base + name.to_s.singularize.camelize).constantize end |
.plural(name) ⇒ Object
74 75 76 77 |
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 74 def self.plural(name) name = to_name(name) name.to_s.pluralize end |
.singular(name) ⇒ Object
69 70 71 72 |
# File 'lib/chef_fixie_shahid/sql_objects.rb', line 69 def self.singular(name) name = to_name(name) name.to_s.singularize end |
.table_class(name) ⇒ Object
The class for the table, e.g. Orgs
58 59 60 61 |
# File 'lib/chef_fixie_shahid/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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chef_fixie_shahid/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 |