Class: Preserves::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/preserves/mapping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_mappingsObject

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_mappingsObject

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_classObject

Returns the value of attribute model_class.



5
6
7
# File 'lib/preserves/mapping.rb', line 5

def model_class
  @model_class
end

#name_mappingsObject

Returns the value of attribute name_mappings.



6
7
8
# File 'lib/preserves/mapping.rb', line 6

def name_mappings
  @name_mappings
end

#repositoryObject

Returns the value of attribute repository.



4
5
6
# File 'lib/preserves/mapping.rb', line 4

def repository
  @repository
end

#type_mappingsObject

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