Class: ActiveRecordInlineSchema::Config::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_inline_schema/config/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, column_name, options) ⇒ Index

Returns a new instance of Index.



12
13
14
15
16
17
# File 'lib/active_record_inline_schema/config/index.rb', line 12

def initialize(parent, column_name, options)
  @parent = parent
  @column_name = column_name
  @initial_options = options.symbolize_keys
  @name_mutex = ::Mutex.new
end

Instance Attribute Details

#column_nameObject (readonly)

Returns the value of attribute column_name.



6
7
8
# File 'lib/active_record_inline_schema/config/index.rb', line 6

def column_name
  @column_name
end

#initial_optionsObject (readonly)

Returns the value of attribute initial_options.



7
8
9
# File 'lib/active_record_inline_schema/config/index.rb', line 7

def initial_options
  @initial_options
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/active_record_inline_schema/config/index.rb', line 5

def parent
  @parent
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/active_record_inline_schema/config/index.rb', line 37

def eql?(other)
  other.is_a?(self.class) and parent == other.parent and column_name == other.column_name and initial_options == other.initial_options
end

#hashObject



41
42
43
# File 'lib/active_record_inline_schema/config/index.rb', line 41

def hash
  [parent, column_name, initial_options].hash
end

#nameObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_record_inline_schema/config/index.rb', line 19

def name
  @name || @name_mutex.synchronize do
    @name ||= begin
      max_name_length = connection.index_name_length
      prototype = connection.index_name model.table_name, :column => column_name
      if prototype.length < max_name_length
        prototype
      else
        prototype[0..(max_name_length-11)] + ::Zlib.crc32(prototype).to_s
      end
    end
  end
end

#optionsObject



33
34
35
# File 'lib/active_record_inline_schema/config/index.rb', line 33

def options
  @initial_options.merge(:column_name => column_name, :name => name)
end