Module: CarrierWave::Meta::ActiveRecord

Defined in:
lib/carrierwave-meta/active_record.rb

Constant Summary collapse

ALLOWED =
%w(width height md5sum image_size file_size content_type)

Instance Method Summary collapse

Instance Method Details

#carrierwave_meta_composed(single_attribute, *args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/carrierwave-meta/active_record.rb', line 6

def carrierwave_meta_composed(single_attribute, *args)
  defined_attrs = args.map do |arg|
    name, to_define = if arg.is_a?(Symbol)
      [arg, ALLOWED]
    elsif arg.is_a?(Hash)
      [arg.keys.first, arg.values.first]
    end

    to_define.map do |attr|
      delegate :"#{name}_#{attr}", to: single_attribute, allow_nil: true
      delegate :"#{name}_#{attr}=", to: single_attribute, allow_nil: true
    end
  end
end