Class: CarrierWave::FuzzyStorage::ActiveRecordSupport
- Inherits:
-
Module
- Object
- Module
- CarrierWave::FuzzyStorage::ActiveRecordSupport
- Defined in:
- lib/carrierwave/fuzzy_storage/active_record_support.rb
Instance Method Summary collapse
- #included(base) ⇒ Object
-
#initialize(default_storage, *mounted_fields) ⇒ ActiveRecordSupport
constructor
A new instance of ActiveRecordSupport.
Constructor Details
#initialize(default_storage, *mounted_fields) ⇒ ActiveRecordSupport
Returns a new instance of ActiveRecordSupport.
6 7 8 9 |
# File 'lib/carrierwave/fuzzy_storage/active_record_support.rb', line 6 def initialize(default_storage, *mounted_fields) @default_storage = default_storage @mounted_fields = mounted_fields.flatten.map(&:to_sym) end |
Instance Method Details
#included(base) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/carrierwave/fuzzy_storage/active_record_support.rb', line 11 def included(base) storage = @default_storage mounted_fields = @mounted_fields mounted_fields.each do |field| base.send(:define_method, "#{field}_storage") do super() || storage end end base.before_create do mounted_fields.each do |field| public_send("#{field}_storage=", storage) end end end |