Module: Architect4r::Adapters::CarrierWave

Includes:
CarrierWave::Mount
Included in:
Model::Node, Model::Relationship
Defined in:
lib/architect4r/adapters/carrier_wave.rb

Instance Method Summary collapse

Instance Method Details

#mount_uploader(column, uploader = nil, options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/architect4r/adapters/carrier_wave.rb', line 14

def mount_uploader(column, uploader = nil, options = {}, &block)
  property "#{column}_data", :cast_to => String
  
  # Init by calling default initializer
  super
  
  # Enable validations
  include ::CarrierWave::Validations::ActiveModel
  validates_integrity_of  column if uploader_option(column.to_sym, :validate_integrity)
  validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
  
  # Add hooks
  after_save :"store_#{column}!"
  before_save :"write_#{column}_identifier"
  after_destroy :"remove_#{column}!"
  
  # These hooks cannot be used until dirty tracking is implemented
  #before_update :"store_previous_model_for_#{column}"
  #after_save :"remove_previously_stored_#{column}"
  
  class_eval <<-RUBY, __FILE__, __LINE__+1
    
    public
    
    def read_uploader(column)
      self.send("#{column}_data")
    end
    
    def write_uploader(column, identifier)
      self.send("#{column}_data=", identifier)
    end
    
  RUBY
end