Module: DataMapper::FastenTheSeatBelt::ClassMethods

Defined in:
lib/dm-fasten-the-seat-belt.rb

Instance Method Summary collapse

Instance Method Details

#fasten_the_seat_belt(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dm-fasten-the-seat-belt.rb', line 29

def fasten_the_seat_belt(options={})
  # Properties
  self.property :filename, String
  self.property :size, Integer, :lazy => true
  self.property :content_type, String, :lazy => true
  self.property :created_at, DateTime, :lazy => true
  self.property :updated_at, DateTime, :lazy => true
    
  self.property :images_are_compressed, DataMapper::Types::Boolean, :lazy => true
    
  # Callbacks to manage the file
  before :save, :save_attributes
  after :save, :save_file
  after :destroy, :delete_directory

  # Options
  if !defined?(Merb) && !options[:file_system_path]
    raise "If you're running dm-fasten-the-seat-belt outside of Merb, you must specifiy :file_system_path in the options"
  end
  
  options[:file_system_path] ||= File.join((defined?(Merb) ? Merb.root : ''), 'public', merb_environment, self.storage_name)
  options[:thumbnails] ||= {}
    
  self.fasten_the_seat_belt_options = options
end

#merb_environmentObject



60
61
62
# File 'lib/dm-fasten-the-seat-belt.rb', line 60

def merb_environment
  (defined?(Merb) ? Merb.env : '')
end

#recreate_thumbnails!Object



55
56
57
58
# File 'lib/dm-fasten-the-seat-belt.rb', line 55

def recreate_thumbnails!
  all.each {|object| object.generate_thumbnails! }
  true
end