Sha256: fda8721f687b76adf14197cedd85daa6c212e69486fd318704e8fbc070f7c215
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
# # File Manager Engine module # # @author Xiterrex & Jnillo # # @description This module extend the entity which is included and add the methods in the callback before_save # to register relation between entity's instance and file included. # require "file_manager_engine/engine" module FileManagerEngine module ClassMethods mattr_accessor :file_field_name end # This static method is use to extend methods in other class which included this class def self.included(base) base.extend(ClassMethods) base.after_save :make_relation_file end # # This method generate a instance in data base for each file relationated with the new document generated # If the content is modifcated, this method remake all relations between file/s and this content. def make_relation_file ary = self.send(self.class.file_field_name.to_sym) to_array(ary).each do |file| FileManager.new({ :entity_type => self.class.name,:entity_id => self.id, :file => file }).save end end private # This methdo has been created to explicit conversion to array elements. def to_array(val) [val].flatten end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
file_manager_engine-0.0.3 | lib/file_manager_engine.rb |
file_manager_engine-0.0.2 | lib/file_manager_engine.rb |
file_manager_engine-0.0.1 | lib/file_manager_engine.rb |