Sha256: d3cf69819f354215d2fa25df530c89304b63ef7e091a699d9b4d9d9afbac19ea

Contents?: true

Size: 973 Bytes

Versions: 6

Compression:

Stored size: 973 Bytes

Contents

module DynamicPaperclip
  class HasAttachedFile < Paperclip::HasAttachedFile
    def register_new_attachment
      DynamicPaperclip::AttachmentRegistry.register(@klass, @name, @options)

      super
    end

    private

      # TODO: Are there any alternatives to literally copying this
      #       method from Paperclip::HasAttachedFile to get Ruby to find
      #       DynamicPaperclip::Attachment instead of Paperclip::Attachment?
      def define_instance_getter
        name = @name
        options = @options

        @klass.send :define_method, @name do |*args|
          ivar = "@attachment_#{name}"
          attachment = instance_variable_get(ivar)

          if attachment.nil?
            attachment = Attachment.new(name, self, options)
            instance_variable_set(ivar, attachment)
          end

          if args.length > 0
            attachment.to_s(args.first)
          else
            attachment
          end
        end
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dynamic_paperclip-1.0.1 lib/dynamic_paperclip/has_attached_file.rb
dynamic_paperclip-1.0.0 lib/dynamic_paperclip/has_attached_file.rb
dynamic_paperclip-1.0.0.alpha.4 lib/dynamic_paperclip/has_attached_file.rb
dynamic_paperclip-1.0.0a.3 lib/dynamic_paperclip/has_attached_file.rb
dynamic_paperclip-1.0.0a.2 lib/dynamic_paperclip/has_attached_file.rb
dynamic_paperclip-1.0.0a.1 lib/dynamic_paperclip/has_attached_file.rb