Sha256: 4a164bef28b1cb9a4c653681dbbcc5b3cd369d479aaf74aeacaeb04485c589eb

Contents?: true

Size: 527 Bytes

Versions: 5

Compression:

Stored size: 527 Bytes

Contents

# frozen_string_literal: true

module DynamicImage
  # = DynamicImage Belongs To
  #
  module BelongsTo
    extend ActiveSupport::Concern

    module ClassMethods
      def belongs_to_image(name, scope = nil, **options)
        belongs_to(name, scope, options)

        define_method "#{name}=" do |new_image|
          if new_image.present? && !new_image.is_a?(DynamicImage::Model)
            new_image = send("build_#{name}", file: new_image)
          end
          super(new_image)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dynamic_image-2.0.21 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.20 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.19 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.18 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.17 lib/dynamic_image/belongs_to.rb