aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-01-08 09:27:25 -0600
committerschneems <richard.schneeman@gmail.com>2016-01-08 09:27:25 -0600
commitde2cb20117af68cef4126d8998cc63e178c58187 (patch)
tree9cfa86dbd308f0ec1cfef9e45e3bcf9276885db0 /activerecord/lib
parenta76c4233a9ee9ffbf413c4b8353e73e8ffbeb3a5 (diff)
downloadrails-de2cb20117af68cef4126d8998cc63e178c58187.tar.gz
rails-de2cb20117af68cef4126d8998cc63e178c58187.tar.bz2
rails-de2cb20117af68cef4126d8998cc63e178c58187.zip
Use hash like syntax for InternalMetadata
Discussion: https://github.com/rails/rails/pull/22967#discussion_r49137035
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/internal_metadata.rb10
-rw-r--r--activerecord/lib/active_record/migration.rb6
-rw-r--r--activerecord/lib/active_record/schema.rb2
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
4 files changed, 9 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb
index fc1bb0bdce..7bd66028b6 100644
--- a/activerecord/lib/active_record/internal_metadata.rb
+++ b/activerecord/lib/active_record/internal_metadata.rb
@@ -4,7 +4,7 @@ require 'active_record/scoping/named'
module ActiveRecord
# This class is used to create a table that keeps track of values and keys such
# as which environment migrations were run in.
- class InternalMetadata < ActiveRecord::Base
+ class InternalMetadata < ActiveRecord::Base # :nodoc:
class << self
def primary_key
"key"
@@ -18,13 +18,11 @@ module ActiveRecord
"#{table_name_prefix}unique_#{ActiveRecord::Base.internal_metadata_table_name}#{table_name_suffix}"
end
- def store(hash)
- hash.each do |key, value|
- first_or_initialize(key: key).update_attributes!(value: value)
- end
+ def []=(key, value)
+ first_or_initialize(key: key).update_attributes!(value: value)
end
- def value_for(key)
+ def [](key)
where(key: key).pluck(:value).first
end
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index a7e747a482..cd1bda3324 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -1233,15 +1233,15 @@ module ActiveRecord
else
migrated << version
ActiveRecord::SchemaMigration.create!(version: version.to_s)
- ActiveRecord::InternalMetadata.store(environment: current_environment)
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
end
def self.last_stored_environment
- ActiveRecord::InternalMetadata.value_for(:environment)
+ ActiveRecord::InternalMetadata[:environment]
end
- def current_environment
+ def self.current_environment
ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
end
diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb
index 0a0ea33196..784a02d2c3 100644
--- a/activerecord/lib/active_record/schema.rb
+++ b/activerecord/lib/active_record/schema.rb
@@ -53,7 +53,7 @@ module ActiveRecord
end
ActiveRecord::InternalMetadata.create_table
- ActiveRecord::InternalMetadata.store("environment" => ActiveRecord::ConnectionHandling::DEFAULT_ENV.call)
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
private
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 92f6f44de9..d51f38c93f 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -221,7 +221,7 @@ module ActiveRecord
raise ArgumentError, "unknown format #{format.inspect}"
end
ActiveRecord::InternalMetadata.create_table
- ActiveRecord::InternalMetata.store("environment" => ActiveRecord::ConnectionHandling::DEFAULT_ENV.call)
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
def load_schema_for(*args)