diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-08-05 09:07:07 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-05 09:07:07 -0500 |
commit | b360f07bd2a43c7fe5f33ae520b1cf3563e54645 (patch) | |
tree | 809dc502e09d6ac2863d56ebf1455ea12bbb9d06 /activestorage/lib/active_storage | |
parent | ea5c99dce1e23b0f8211583d6cb7846d9e303971 (diff) | |
parent | 46db463d068d9b24c99f11a1c78dac1c1bfb45c2 (diff) | |
download | rails-b360f07bd2a43c7fe5f33ae520b1cf3563e54645.tar.gz rails-b360f07bd2a43c7fe5f33ae520b1cf3563e54645.tar.bz2 rails-b360f07bd2a43c7fe5f33ae520b1cf3563e54645.zip |
Merge pull request #30081 from y-yagi/fix_ruby_warnings
Fix ruby warnings
Diffstat (limited to 'activestorage/lib/active_storage')
-rw-r--r-- | activestorage/lib/active_storage/attached/macros.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/attached/macros.rb b/activestorage/lib/active_storage/attached/macros.rb index 89297e5bdf..f09f3e1f6d 100644 --- a/activestorage/lib/active_storage/attached/macros.rb +++ b/activestorage/lib/active_storage/attached/macros.rb @@ -22,8 +22,11 @@ module ActiveStorage::Attached::Macros # (i.e. destroyed) whenever the record is destroyed. def has_one_attached(name, dependent: :purge_later) define_method(name) do - instance_variable_get("@active_storage_attached_#{name}") || + if instance_variable_defined?("@active_storage_attached_#{name}") + instance_variable_get("@active_storage_attached_#{name}") + else instance_variable_set("@active_storage_attached_#{name}", ActiveStorage::Attached::One.new(name, self)) + end end has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record @@ -60,8 +63,11 @@ module ActiveStorage::Attached::Macros # (i.e. destroyed) whenever the record is destroyed. def has_many_attached(name, dependent: :purge_later) define_method(name) do - instance_variable_get("@active_storage_attached_#{name}") || + if instance_variable_defined?("@active_storage_attached_#{name}") + instance_variable_get("@active_storage_attached_#{name}") + else instance_variable_set("@active_storage_attached_#{name}", ActiveStorage::Attached::Many.new(name, self)) + end end has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment" |