Module: Progstr::Filer::ActiveRecordInstanceMethods
- Defined in:
- lib/filer/activerecord.rb
Instance Method Summary collapse
- #_attachments ⇒ Object
- #_attachments_to_delete ⇒ Object
- #_delete_expired_attachments ⇒ Object
- #_expire_all_attachments ⇒ Object
- #_filer_after_save ⇒ Object
- #_filer_before_delete ⇒ Object
- #_get_attachment(attribute) ⇒ Object
- #_set_attachment(attribute, value) ⇒ Object
- #_upload_attachment(attribute) ⇒ Object
- #_upload_attachments ⇒ Object
Instance Method Details
#_attachments ⇒ Object
36 37 38 39 |
# File 'lib/filer/activerecord.rb', line 36 def @_filer_attachments ||= {} @_filer_attachments end |
#_attachments_to_delete ⇒ Object
41 42 43 44 |
# File 'lib/filer/activerecord.rb', line 41 def @_filer_attachments_to_delete ||= [] @_filer_attachments_to_delete end |
#_delete_expired_attachments ⇒ Object
101 102 103 104 105 106 |
# File 'lib/filer/activerecord.rb', line 101 def .each do || uploader = self.class._uploaders[.attribute] uploader.() unless uploader.nil? end end |
#_expire_all_attachments ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/filer/activerecord.rb', line 113 def # trigger entity load dummy = read_attribute(:dummy) self.class._uploaders.each do |item| attribute = item[0] #load attachment object dummy = (attribute) #schedule it for deletion (attribute, nil) end end |
#_filer_after_save ⇒ Object
108 109 110 111 |
# File 'lib/filer/activerecord.rb', line 108 def _filer_after_save end |
#_filer_before_delete ⇒ Object
125 126 127 128 |
# File 'lib/filer/activerecord.rb', line 125 def _filer_before_delete end |
#_get_attachment(attribute) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/filer/activerecord.rb', line 46 def (attribute) if [attribute].nil? id = read_attribute(attribute) uploader_class = self.class._uploaders[attribute].class if id.nil? [attribute] = Attachment.empty(uploader_class) else [attribute] = Attachment.from_id(uploader_class, attribute, id) end else [attribute] end end |
#_set_attachment(attribute, value) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/filer/activerecord.rb', line 60 def (attribute, value) = (attribute) unless .blank? << end uploader_class = self.class._uploaders[attribute].class if value.kind_of?(String) = nil if value.include?("{") = Attachment.from_json(uploader_class, attribute, value) else = Attachment.from_id(uploader_class, attribute, value) end [attribute] = write_attribute(attribute, .id) elsif !value.nil? #file-like = Attachment.from_file(uploader_class, attribute, value) [attribute] = write_attribute(attribute, .id) else [attribute] = nil write_attribute(attribute, nil) end end |
#_upload_attachment(attribute) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/filer/activerecord.rb', line 93 def (attribute) = (attribute) if .need_upload? uploader = self.class._uploaders[attribute] uploader.() unless uploader.nil? end end |
#_upload_attachments ⇒ Object
86 87 88 89 90 91 |
# File 'lib/filer/activerecord.rb', line 86 def self.class._uploaders.each do |item| attribute = item[0] (attribute) end end |