Class: Lipsiadmin::DataBase::AttachmentTable
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lipsiadmin::DataBase::AttachmentTable
- Defined in:
- lib/data_base/attachment_table.rb
Overview
This is the table that handle the attachments. You can define some global info like:
:thumb, "128x128"
In this way all models that use has_one_attachment
or has_many_attachments
handle a default style called thumb
Remember that any model that use has_one_attachment
or has_many_attachments
can override/add styles/validations etc…
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#attachment_definitions ⇒ Object
This is the custom instance attachment_definition.
-
#attachment_definitions=(options) ⇒ Object
:nodoc:.
-
#destroy_attached_files ⇒ Object
Perform
file
.destroy. -
#file ⇒ Object
Returns a
Lipsiadmin::Attachment::Attach
instance. -
#file=(tempfile) ⇒ Object
Assign a
Lipsiadmin::Attachment::Attach
instance to the current file. -
#file? ⇒ Boolean
Returns true if the file exist.
-
#save_attached_files ⇒ Object
Perform
file
.save. -
#url(style = nil) ⇒ Object
Returns the url of the attachment, optionally you can pass the style like url(:thumb).
Class Method Details
.inherited(subclass) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 |
# File 'lib/data_base/attachment_table.rb', line 15 def self.inherited(subclass)#:nodoc: super subclass.write_inheritable_attribute(:attachment_definitions, {}) if subclass..nil? subclass.[subclass.name] = {:validations => {}}.merge(Lipsiadmin::Attachment.) subclass.send(:include, Lipsiadmin::DataBase::UtilityScopes) subclass.extend(ClassMethods) end |
Instance Method Details
#attachment_definitions ⇒ Object
This is the custom instance attachment_definition
58 59 60 61 |
# File 'lib/data_base/attachment_table.rb', line 58 def #:nodoc: @instance_attachment_definitions ||= self.class.[self.class.name].clone return @instance_attachment_definitions end |
#attachment_definitions=(options) ⇒ Object
:nodoc:
53 54 55 |
# File 'lib/data_base/attachment_table.rb', line 53 def ()#:nodoc: .merge!(.symbolize_keys) end |
#destroy_attached_files ⇒ Object
Perform file
.destroy
75 76 77 78 79 |
# File 'lib/data_base/attachment_table.rb', line 75 def destroy_attached_files logger.info("[Attachment] Deleting attachments.") file.queue_existing_for_delete file.flush_deletes end |
#file ⇒ Object
Returns a Lipsiadmin::Attachment::Attach
instance
39 40 41 |
# File 'lib/data_base/attachment_table.rb', line 39 def file @_file ||= Lipsiadmin::Attachment::Attach.new(:attached, self, ) end |
#file=(tempfile) ⇒ Object
Assign a Lipsiadmin::Attachment::Attach
instance to the current file
44 45 46 |
# File 'lib/data_base/attachment_table.rb', line 44 def file=(tempfile) file.assign(tempfile) end |
#file? ⇒ Boolean
Returns true if the file exist
49 50 51 |
# File 'lib/data_base/attachment_table.rb', line 49 def file? file.exist? end |
#save_attached_files ⇒ Object
Perform file
.save
69 70 71 72 |
# File 'lib/data_base/attachment_table.rb', line 69 def save_attached_files logger.info("[Attachment] Saving attachments.") file.save end |
#url(style = nil) ⇒ Object
Returns the url of the attachment, optionally you can pass the style like url(:thumb)
34 35 36 |
# File 'lib/data_base/attachment_table.rb', line 34 def url(style=nil) file.url(style) end |