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.



59
60
61
# File 'lib/rails_uploads/active_record/base.rb', line 59

def attachments
  @attachments
end

Class Method Details

.extended(base) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/rails_uploads/active_record/base.rb', line 61

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



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

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

#inherited(subclass) ⇒ Object



77
78
79
80
# File 'lib/rails_uploads/active_record/base.rb', line 77

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

#is_attachable?Boolean

Returns:

  • (Boolean)


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

def is_attachable?
  attachments.present?
end