Module: CarrierWave::Neo4j::ClassMethods
- Includes:
- Mount
- Defined in:
- lib/carrierwave/neo4j.rb
Instance Method Summary collapse
-
#mount_uploader(column, uploader = nil, options = {}, &block) ⇒ Object
See CarrierWave::Mount#mount_uploader for documentation.
Instance Method Details
#mount_uploader(column, uploader = nil, options = {}, &block) ⇒ Object
See CarrierWave::Mount#mount_uploader for documentation
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/carrierwave/neo4j.rb', line 17 def mount_uploader(column, uploader = nil, = {}, &block) super serialize column, ::CarrierWave::Uploader::Base 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) after_save :"store_#{column}!" before_save :"write_#{column}_identifier" before_destroy :"clear_#{column}" after_destroy :"remove_#{column}!" class_eval <<-RUBY, __FILE__, __LINE__+1 def #{column}=(new_file) column = _mounter(:#{column}).serialization_column send(:attribute_will_change!, :#{column}) super end def remote_#{column}_url=(url) column = _mounter(:#{column}).serialization_column send(:attribute_will_change!, :#{column}) super end def clear_#{column} write_uploader(_mounter(:#{column}).serialization_column, nil) end def read_uploader(name) send(:attribute, name.to_s) end def write_uploader(name, value) send(:attribute=, name.to_s, value) end def reload_from_database if reloaded = self.class.load_entity(neo_id) send(:attributes=, reloaded.attributes.reject{ |k,v| v.is_a?(::CarrierWave::Uploader::Base) }) end reloaded end # carrierwave keeps a instance variable of @uploaders, cached at init time # but at init time, the value of the column is not yet available # so after init, the empty @uploaders cache must be invalidated # it will reinitialized with the processed column value on first access unless method_defined?(:_set_uploaders_nil) after_initialize :_set_uploaders_nil def _set_uploaders_nil if @_mounters @_mounters.each do |_, mounter| mounter.instance_variable_set(:@uploaders, nil) end end end end RUBY end |