Class: ActiveRecord::InternalMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/internal_metadata_extensions.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



15
16
17
# File 'lib/active_record/internal_metadata_extensions.rb', line 15

def [](key)
  where(key: key).pluck(value_name).first
end

.[]=(key, value) ⇒ Object



11
12
13
# File 'lib/active_record/internal_metadata_extensions.rb', line 11

def []=(key, value)
  find_or_initialize_by(key: key).update!(value_name => value)
end

.adapter_nameObject



3
4
5
# File 'lib/active_record/internal_metadata_extensions.rb', line 3

def adapter_name
  connection.adapter_name.downcase.to_sym
end

.create_tableObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_record/internal_metadata_extensions.rb', line 19

def create_table
  unless table_exists?
    key_options = connection.internal_string_options_for_primary_key

    connection.create_table(table_name, id: false) do |t|
      t.string :key, key_options
      t.string value_name
      t.timestamps
    end
  end
end

.value_nameObject



7
8
9
# File 'lib/active_record/internal_metadata_extensions.rb', line 7

def value_name
  adapter_name == :firebird ? :value_ : :value
end