diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-08-05 12:21:21 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-08-05 12:22:39 +0900 |
commit | 46db463d068d9b24c99f11a1c78dac1c1bfb45c2 (patch) | |
tree | a85164df8a161609d2b00ee5268888ffdfaab05b /activestorage/lib/active_storage | |
parent | 95ad242c8066e71c403d53ea634f347e357473b1 (diff) | |
download | rails-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/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" |