aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-08-05 12:21:21 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-08-05 12:22:39 +0900
commit46db463d068d9b24c99f11a1c78dac1c1bfb45c2 (patch)
treea85164df8a161609d2b00ee5268888ffdfaab05b /activestorage/lib
parent95ad242c8066e71c403d53ea634f347e357473b1 (diff)
downloadrails-46db463d068d9b24c99f11a1c78dac1c1bfb45c2.tar.gz
rails-46db463d068d9b24c99f11a1c78dac1c1bfb45c2.tar.bz2
rails-46db463d068d9b24c99f11a1c78dac1c1bfb45c2.zip
Fix ruby warnings
This fixes following warnings: ``` test/models/variant_test.rb:11: warning: ambiguous first argument; put parentheses or a space even after `/' operator lib/active_storage/attached/macros.rb:63: warning: instance variable @active_storage_attached_highlights not initialized lib/active_storage/attached/macros.rb:25: warning: instance variable @active_storage_attached_avatar not initialized ```
Diffstat (limited to 'activestorage/lib')
-rw-r--r--activestorage/lib/active_storage/attached/macros.rb10
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"