Class: EmptyEye::PrimaryShard
- Inherits:
-
Object
- Object
- EmptyEye::PrimaryShard
- Defined in:
- lib/empty_eye/primary_shard.rb
Class Method Summary collapse
- .connection ⇒ Object
-
.exclude_always ⇒ Object
never include the type field as it shouldnt be needed and cant be updated anyway.
Instance Method Summary collapse
-
#arel_table ⇒ Object
arel table for generating the view.
-
#columns ⇒ Object
the table columns that will be extended in sql.
-
#delegate_to(col, shard) ⇒ Object
delegate setters to appropriate associations.
- #exclude ⇒ Object
- #foreign_key ⇒ Object
-
#has_another(shard) ⇒ Object
create associations for shard class to mimic master_class.
-
#initialize(wrangler) ⇒ PrimaryShard
constructor
primary shard for master_class class manages associations for database updates has many of the same interfaces as view shards.
-
#key ⇒ Object
this may change but for now the key is the primary id of the master_class and shard.
-
#klass ⇒ Object
class that will mimic the associations of the master_class for updating db.
-
#master_class ⇒ Object
class to which this shard belongs.
-
#name ⇒ Object
the alias for the table; for primary we just use the table name.
-
#polymorphic_type ⇒ Object
always null for primary.
-
#primary ⇒ Object
to let the outside word know it is primary.
- #sti_also? ⇒ Boolean
-
#table ⇒ Object
the tablename.
-
#table_columns ⇒ Object
table columns.
-
#type_column ⇒ Object
arel column of type field.
-
#type_value ⇒ Object
value of the polymorphic column.
Constructor Details
#initialize(wrangler) ⇒ PrimaryShard
primary shard for master_class class manages associations for database updates has many of the same interfaces as view shards
8 9 10 11 12 |
# File 'lib/empty_eye/primary_shard.rb', line 8 def initialize(wrangler) @table = wrangler.table_name @master_class = wrangler.master_class @klass = wrangler end |
Class Method Details
.connection ⇒ Object
14 15 16 |
# File 'lib/empty_eye/primary_shard.rb', line 14 def self.connection ActiveRecord::Base.connection end |
.exclude_always ⇒ Object
never include the type field as it shouldnt be needed and cant be updated anyway
19 20 21 |
# File 'lib/empty_eye/primary_shard.rb', line 19 def self.exclude_always ['type', 'mti_schema_version'] end |
Instance Method Details
#arel_table ⇒ Object
arel table for generating the view
49 50 51 |
# File 'lib/empty_eye/primary_shard.rb', line 49 def arel_table @arel_table ||= Arel::Table.new(table) end |
#columns ⇒ Object
the table columns that will be extended in sql
94 95 96 |
# File 'lib/empty_eye/primary_shard.rb', line 94 def columns table_columns - exclude end |
#delegate_to(col, shard) ⇒ Object
delegate setters to appropriate associations
111 112 113 114 |
# File 'lib/empty_eye/primary_shard.rb', line 111 def delegate_to(col, shard) return if shard.primary klass.send(:delegate, "#{col}=", {:to => shard.name}) end |
#exclude ⇒ Object
89 90 91 |
# File 'lib/empty_eye/primary_shard.rb', line 89 def exclude self.class.exclude_always end |
#foreign_key ⇒ Object
58 59 60 |
# File 'lib/empty_eye/primary_shard.rb', line 58 def foreign_key "id" end |
#has_another(shard) ⇒ Object
create associations for shard class to mimic master_class
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/empty_eye/primary_shard.rb', line 99 def has_another(shard) #this is myself; dont associate return if shard.primary mimic = shard.association return if klass.reflect_on_association(mimic.name) = mimic..dup .merge!() .merge!(:foreign_key => shard.foreign_key) klass.send(mimic.macro, mimic.name, ) end |
#key ⇒ Object
this may change but for now the key is the primary id of the master_class and shard
54 55 56 |
# File 'lib/empty_eye/primary_shard.rb', line 54 def key arel_table[:id] end |
#klass ⇒ Object
class that will mimic the associations of the master_class for updating db
34 35 36 |
# File 'lib/empty_eye/primary_shard.rb', line 34 def klass @klass end |
#master_class ⇒ Object
class to which this shard belongs
24 25 26 |
# File 'lib/empty_eye/primary_shard.rb', line 24 def master_class @master_class end |
#name ⇒ Object
the alias for the table; for primary we just use the table name
44 45 46 |
# File 'lib/empty_eye/primary_shard.rb', line 44 def name @table end |
#polymorphic_type ⇒ Object
always null for primary
79 80 81 |
# File 'lib/empty_eye/primary_shard.rb', line 79 def polymorphic_type nil end |
#primary ⇒ Object
to let the outside word know it is primary
29 30 31 |
# File 'lib/empty_eye/primary_shard.rb', line 29 def primary true end |
#sti_also? ⇒ Boolean
62 63 64 |
# File 'lib/empty_eye/primary_shard.rb', line 62 def sti_also? !master_class.descends_from_active_record? end |
#table ⇒ Object
the tablename
39 40 41 |
# File 'lib/empty_eye/primary_shard.rb', line 39 def table @table end |
#table_columns ⇒ Object
table columns
84 85 86 87 |
# File 'lib/empty_eye/primary_shard.rb', line 84 def table_columns klass.column_names #self.class.connection.columns(table).collect(&:name) end |
#type_column ⇒ Object
arel column of type field
67 68 69 70 71 |
# File 'lib/empty_eye/primary_shard.rb', line 67 def type_column if sti_also? arel_table[master_class.inheritance_column.to_sym] end end |
#type_value ⇒ Object
value of the polymorphic column
74 75 76 |
# File 'lib/empty_eye/primary_shard.rb', line 74 def type_value master_class.name if type_column end |