Module: Attachs::ActiveRecord::Base::ClassMethods

Defined in:
lib/attachs/active_record/base.rb

Instance Method Summary collapse

Instance Method Details

#attachable?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/attachs/active_record/base.rb', line 68

def attachable?
  attachments.any?
end

#attachmentsObject



64
65
66
# File 'lib/attachs/active_record/base.rb', line 64

def attachments
  @attachments ||= {}
end

#has_attached_file(*args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/attachs/active_record/base.rb', line 53

def has_attached_file(*args)
  options = args.extract_options!
  unless attachable?
    make_attachable
  end
  args.each do |attr|
    define_attachment_methods attr, options
    attachments[attr] = options
  end
end

#inherited(subclass) ⇒ Object



72
73
74
75
# File 'lib/attachs/active_record/base.rb', line 72

def inherited(subclass)
  subclass.instance_variable_set :@attachments, @attachments
  super
end