Sha256: 1f6a306329ff8efb5948a020b0ab31e5f895db391f753d117e52bf21ce61c60a

Contents?: true

Size: 521 Bytes

Versions: 8

Compression:

Stored size: 521 Bytes

Contents

# encoding: utf-8

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.kind_of?(DynamicImage::Model)
            new_image = self.send("build_#{name}", file: new_image)
          end
          super(new_image)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dynamic_image-2.0.0 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta7 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta6 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta5 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta4 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta3 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta2 lib/dynamic_image/belongs_to.rb
dynamic_image-2.0.0.beta1 lib/dynamic_image/belongs_to.rb