Module: Bulldog::HasAttachment

Defined in:
lib/bulldog/has_attachment.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Method Summary collapse

Instance Method Details

#has_attachment(name, &block) ⇒ Object

Declare that this model has an attachment.

TODO: example that shows all the options.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bulldog/has_attachment.rb', line 8

def has_attachment(name, &block)
  unless include?(InstanceMethods)
    extend ClassMethods
    include InstanceMethods
  end

  reflection = attachment_reflections[name] || Reflection.new(self, name)
  reflection.configure(&block)
  unless attachment_reflections.key?(name)
    attachment_reflections[name] = reflection
    define_attachment_accessors(reflection.name)
    define_attachment_attribute_methods(reflection.name)
  end
end