Class: ActiveRecord::InternalMetadata
- Inherits:
-
Object
- Object
- ActiveRecord::InternalMetadata
- Defined in:
- lib/active_record/internal_metadata_extensions.rb
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .adapter_name ⇒ Object
- .create_table ⇒ Object
- .value_name ⇒ Object
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_name ⇒ Object
3 4 5 |
# File 'lib/active_record/internal_metadata_extensions.rb', line 3 def adapter_name connection.adapter_name.downcase.to_sym end |
.create_table ⇒ Object
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? = connection. connection.create_table(table_name, id: false) do |t| t.string :key, t.string value_name t. end end end |
.value_name ⇒ Object
7 8 9 |
# File 'lib/active_record/internal_metadata_extensions.rb', line 7 def value_name adapter_name == :firebird ? :value_ : :value end |