Module: Shrine::Attacher::ClassMethods

Included in:
Shrine::Attacher
Defined in:
lib/shrine/attacher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#shrine_classObject

Returns the Shrine class that this attacher class is namespaced under.



12
13
14
# File 'lib/shrine/attacher.rb', line 12

def shrine_class
  @shrine_class
end

Instance Method Details

#inspectObject

Since Attacher is anonymously subclassed when Shrine is subclassed, and then assigned to a constant of the Shrine subclass, make inspect reflect the likely name for the class.



17
18
19
# File 'lib/shrine/attacher.rb', line 17

def inspect
  "#{shrine_class.inspect}::Attacher"
end

#validate(&block) ⇒ Object

Block that is executed in context of Shrine::Attacher during validation. Example:

Shrine::Attacher.validate do
  if get.size > 5*1024*1024
    errors << "is too big (max is 5 MB)"
  end
end


29
30
31
32
# File 'lib/shrine/attacher.rb', line 29

def validate(&block)
  define_method(:validate_block, &block)
  private :validate_block
end