module Shrine::Plugins::Base::AttachmentMethods

  1. lib/shrine.rb

Methods

Public Class

  1. new

Public Instance

  1. attachment_name
  2. inspect
  3. options
  4. shrine_class
  5. to_s

Public Class methods

new (name, **options)

Instantiates an attachment module for a given attribute name, which can then be included to a model class. Second argument will be passed to an attacher module.

[show source]
# File lib/shrine.rb, line 394
        def initialize(name, **options)
          @name    = name
          @options = options

          module_eval "            def #{name}_attacher
              @#{name}_attacher ||= (
                attachments    = self.class.ancestors.grep(Shrine::Attachment)
                attachment     = attachments.find { |mod| mod.attachment_name == :#{name} }
                attacher_class = attachment.shrine_class::Attacher
                options        = attachment.options

                attacher_class.new(self, :#{name}, options)
              )
            end

            def #{name}=(value)
              #{name}_attacher.assign(value)
            end

            def #{name}
              #{name}_attacher.get
            end

            def #{name}_url(*args)
              #{name}_attacher.url(*args)
            end
", __FILE__, __LINE__ + 1
        end

Public Instance methods

attachment_name ()

Returns name of the attachment this module provides.

[show source]
# File lib/shrine.rb, line 425
def attachment_name
  @name
end
inspect ()

Returns class name with attachment name included.

Shrine[:image].inspect #=> "#<Shrine::Attachment(image)>"
[show source]
# File lib/shrine.rb, line 444
def inspect
  "#<#{self.class.inspect}(#{attachment_name})>"
end
options ()

Returns options that are to be passed to the Attacher.

[show source]
# File lib/shrine.rb, line 430
def options
  @options
end
shrine_class ()

Returns the Shrine class that this attachment's class is namespaced under.

[show source]
# File lib/shrine.rb, line 450
def shrine_class
  self.class.shrine_class
end
to_s ()

Returns class name with attachment name included.

Shrine[:image].to_s #=> "#<Shrine::Attachment(image)>"
[show source]
# File lib/shrine.rb, line 437
def to_s
  "#<#{self.class.inspect}(#{attachment_name})>"
end