Class: Preserves::Mapping
- Inherits:
-
Object
- Object
- Preserves::Mapping
- Defined in:
- lib/preserves/mapping.rb
Instance Attribute Summary collapse
-
#belongs_to_mappings ⇒ Object
Returns the value of attribute belongs_to_mappings.
-
#has_many_mappings ⇒ Object
Returns the value of attribute has_many_mappings.
-
#model_class ⇒ Object
Returns the value of attribute model_class.
-
#name_mappings ⇒ Object
Returns the value of attribute name_mappings.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#type_mappings ⇒ Object
Returns the value of attribute type_mappings.
Instance Method Summary collapse
-
#initialize(repository, model_class, &block) ⇒ Mapping
constructor
A new instance of Mapping.
-
#primary_key(key_name = nil) ⇒ Object
Note that this works to set or get the primary key.
-
#table_name(name = nil) ⇒ Object
Note that this works to set or get the table name.
Constructor Details
#initialize(repository, model_class, &block) ⇒ Mapping
Returns a new instance of Mapping.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/preserves/mapping.rb', line 11 def initialize(repository, model_class, &block) table_name pluralize(model_class.name.downcase) primary_key "id" self.repository = repository self.model_class = model_class self.name_mappings = {} self.type_mappings = {} self.has_many_mappings = {} self.belongs_to_mappings = {} self.instance_eval(&block) end |
Instance Attribute Details
#belongs_to_mappings ⇒ Object
Returns the value of attribute belongs_to_mappings.
9 10 11 |
# File 'lib/preserves/mapping.rb', line 9 def belongs_to_mappings @belongs_to_mappings end |
#has_many_mappings ⇒ Object
Returns the value of attribute has_many_mappings.
8 9 10 |
# File 'lib/preserves/mapping.rb', line 8 def has_many_mappings @has_many_mappings end |
#model_class ⇒ Object
Returns the value of attribute model_class.
5 6 7 |
# File 'lib/preserves/mapping.rb', line 5 def model_class @model_class end |
#name_mappings ⇒ Object
Returns the value of attribute name_mappings.
6 7 8 |
# File 'lib/preserves/mapping.rb', line 6 def name_mappings @name_mappings end |
#repository ⇒ Object
Returns the value of attribute repository.
4 5 6 |
# File 'lib/preserves/mapping.rb', line 4 def repository @repository end |
#type_mappings ⇒ Object
Returns the value of attribute type_mappings.
7 8 9 |
# File 'lib/preserves/mapping.rb', line 7 def type_mappings @type_mappings end |
Instance Method Details
#primary_key(key_name = nil) ⇒ Object
Note that this works to set or get the primary key. TODO: We don’t want to allow publicly setting this, but we need to publicly get it.
32 33 34 35 |
# File 'lib/preserves/mapping.rb', line 32 def primary_key(key_name=nil) @primary_key = key_name unless key_name.nil? @primary_key end |
#table_name(name = nil) ⇒ Object
Note that this works to set or get the table name. TODO: We don’t want to allow publicly setting this, but we need to publicly get it.
25 26 27 28 |
# File 'lib/preserves/mapping.rb', line 25 def table_name(name=nil) @table_name = name unless name.nil? @table_name end |