Module: Attachie::ClassMethods

Defined in:
lib/attachie.rb

Instance Method Summary collapse

Instance Method Details

#attachment(name, options = {}) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/attachie.rb', line 170

def attachment(name, options = {})
  self.attachments = attachments.merge(name => options)

  define_method name do |version = nil, options = {}|
    return instance_variable_get("@#{name}") if version.nil?

    attachment(name).version(version, options)
  end

  define_method "#{name}=" do |value|
    self.updated_at = Time.now if respond_to?(:updated_at=) && !value.nil?

    instance_variable_set "@#{name}", value
  end
end