Class: HoboFields::HabtmModelShim

Inherits:
Struct
  • Object
show all
Defined in:
lib/hobo_fields/migration_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection

Returns:

  • (Object)

    the current value of connection



5
6
7
# File 'lib/hobo_fields/migration_generator.rb', line 5

def connection
  @connection
end

#foreign_keysObject

Returns the value of attribute foreign_keys

Returns:

  • (Object)

    the current value of foreign_keys



5
6
7
# File 'lib/hobo_fields/migration_generator.rb', line 5

def foreign_keys
  @foreign_keys
end

#join_tableObject

Returns the value of attribute join_table

Returns:

  • (Object)

    the current value of join_table



5
6
7
# File 'lib/hobo_fields/migration_generator.rb', line 5

def join_table
  @join_table
end

Class Method Details

.from_reflection(refl) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/hobo_fields/migration_generator.rb', line 7

def self.from_reflection(refl)
  result = self.new
  result.join_table = refl.options[:join_table].to_s
  result.foreign_keys = [refl.primary_key_name.to_s, refl.association_foreign_key.to_s].sort
  # this may fail in weird ways if HABTM is running across two DB connections (assuming that's even supported)
  # figure that anybody who sets THAT up can deal with their own migrations...
  result.connection = refl.active_record.connection
  result
end

Instance Method Details

#field_specsObject



21
22
23
24
25
26
27
28
29
# File 'lib/hobo_fields/migration_generator.rb', line 21

def field_specs
  i = 0
  foreign_keys.inject({}) do |h, v|
    # some trickery to avoid an infinite loop when FieldSpec#initialize tries to call model.field_specs
    h[v] = FieldSpec.new(self, v, :integer, :position => i)
    i += 1
    h
  end
end

#index_specsObject



35
36
37
# File 'lib/hobo_fields/migration_generator.rb', line 35

def index_specs
  []
end

#primary_keyObject



31
32
33
# File 'lib/hobo_fields/migration_generator.rb', line 31

def primary_key
  false
end

#table_nameObject



17
18
19
# File 'lib/hobo_fields/migration_generator.rb', line 17

def table_name
  self.join_table
end