aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage/attached
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2018-05-17 14:22:00 -0700
committerJosh Susser <josh@hasmanythrough.com>2018-05-17 14:51:15 -0700
commitfd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9 (patch)
treea3c0cdc07acdae23fee748605c8b19a6a9f81462 /activestorage/lib/active_storage/attached
parent6c05728a507fe828647c2a0f62cf8ede1534a642 (diff)
downloadrails-fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9.tar.gz
rails-fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9.tar.bz2
rails-fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9.zip
Generate getter and setter methods in mixin
Generated attachment getter and setter methods are created within the model's `GeneratedAssociationMethods` module to allow overriding and composition using `super`. Includes tests for new functionality. Co-authored-by: Josh Susser <josh@hasmanythrough.com> Co-authored-by: Jamon Douglas <terrildouglas@gmail.com>
Diffstat (limited to 'activestorage/lib/active_storage/attached')
-rw-r--r--activestorage/lib/active_storage/attached/macros.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/attached/macros.rb b/activestorage/lib/active_storage/attached/macros.rb
index 819f00cc06..f99cf35680 100644
--- a/activestorage/lib/active_storage/attached/macros.rb
+++ b/activestorage/lib/active_storage/attached/macros.rb
@@ -28,7 +28,7 @@ module ActiveStorage
# If the +:dependent+ option isn't set, the attachment will be purged
# (i.e. destroyed) whenever the record is destroyed.
def has_one_attached(name, dependent: :purge_later)
- class_eval <<-CODE, __FILE__, __LINE__ + 1
+ generated_association_methods.class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"})
end
@@ -75,7 +75,7 @@ module ActiveStorage
# If the +:dependent+ option isn't set, all the attachments will be purged
# (i.e. destroyed) whenever the record is destroyed.
def has_many_attached(name, dependent: :purge_later)
- class_eval <<-CODE, __FILE__, __LINE__ + 1
+ generated_association_methods.class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::Many.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"})
end