module Shrine::Plugins::Base::AttachmentMethods

  1. lib/shrine.rb

Methods

Public Class

  1. new

Public Instance

  1. inspect
  2. shrine_class
  3. to_s

Public Class methods

new (name)

Instantiates an attachment module for a given attribute name, which can then be included to a model class.

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

          # We store the attacher class so that the model can instantiate the
          # correct attacher instance.
          class_variable_set(:"@@#{name}_attacher_class", shrine_class::Attacher)

          module_eval "            def #{name}_attacher
              @#{name}_attacher ||= @@#{name}_attacher_class.new(self, :#{name})
            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

inspect ()

Includes the attachment name in the output.

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

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

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

Includes the attachment name in the output.

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