Class: EmptyEye::Shard

Inherits:
Object
  • Object
show all
Defined in:
lib/empty_eye/shard.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association) ⇒ Shard

shard for master_class class tracks associations for database updates managed by primary shard has many of the same interfaces as primary view shard



8
9
10
# File 'lib/empty_eye/shard.rb', line 8

def initialize(association)
  @association = association
end

Class Method Details

.exclude_alwaysObject

exclude from view generation always



13
14
15
# File 'lib/empty_eye/shard.rb', line 13

def self.exclude_always
  ['id','created_at','updated_at','deleted_at', 'type', 'mti_schema_version']
end

Instance Method Details

#arel_tableObject

used to create view



43
44
45
46
47
48
49
# File 'lib/empty_eye/shard.rb', line 43

def arel_table
  @arel_table ||= begin
    t= Arel::Table.new(table)
    t.table_alias = alias_name if alias_name != table
    t
  end
end

#associationObject

association that this shard will build upon



18
19
20
# File 'lib/empty_eye/shard.rb', line 18

def association
  @association
end

#columnsObject

the table columns that will be extended in sql



23
24
25
# File 'lib/empty_eye/shard.rb', line 23

def columns
  restrictions - exclude
end

#foreign_keyObject

foreign key of the shard; used in view generation and database updates



52
53
54
# File 'lib/empty_eye/shard.rb', line 52

def foreign_key
  association.foreign_key 
end

#klassObject



56
57
58
# File 'lib/empty_eye/shard.rb', line 56

def klass
  association.klass
end

#nameObject

name of the association



38
39
40
# File 'lib/empty_eye/shard.rb', line 38

def name
  association.name
end

#polymorphic_typeObject



70
71
72
73
# File 'lib/empty_eye/shard.rb', line 70

def polymorphic_type
  return unless association.options[:as]
  "#{association.options[:as]}_type"
end

#primaryObject

never the primary



28
29
30
# File 'lib/empty_eye/shard.rb', line 28

def primary
  false
end

#tableObject

table of the shard



33
34
35
# File 'lib/empty_eye/shard.rb', line 33

def table
  association.table_name
end

#type_columnObject

arel column of polymorphic type field



61
62
63
# File 'lib/empty_eye/shard.rb', line 61

def type_column
  arel_table[polymorphic_type.to_sym] if polymorphic_type
end

#type_valueObject

value of the polymorphic column



66
67
68
# File 'lib/empty_eye/shard.rb', line 66

def type_value
  master_class.base_class.name if polymorphic_type
end