Module: RailsUploads::ActiveRecord::Base::ClassMethods

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



62
63
64
# File 'lib/rails_uploads/active_record/base.rb', line 62

def attachments
  @attachments
end

Class Method Details

.extended(base) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/rails_uploads/active_record/base.rb', line 64

def self.extended(base)
  [:image].each do |type|
    base.send(:define_singleton_method, "attached_#{type}") do |*args|
      options = args.extract_options!
      options[:type] = type
      attached_file *args.append(options)
    end
  end
end

Instance Method Details

#attached_file(*args) ⇒ Object



74
75
76
77
78
# File 'lib/rails_uploads/active_record/base.rb', line 74

def attached_file(*args)
  options = args.extract_options!
  options.reverse_merge! type: :file
  define_attachment *args.append(options)
end

#inherited(subclass) ⇒ Object



80
81
82
83
# File 'lib/rails_uploads/active_record/base.rb', line 80

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

#is_attachable?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/rails_uploads/active_record/base.rb', line 85

def is_attachable?
  attachments.present?
end