Module: Attachinary::FileMixin
- Included in:
- File
- Defined in:
- lib/attachinary/orm/file_mixin.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #fullpath(options = {}) ⇒ Object
- #path(custom_format = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/attachinary/orm/file_mixin.rb', line 3 def self.included(base) base.validates :public_id, :version, :resource_type, presence: true if Rails::VERSION::MAJOR == 3 base.attr_accessible :public_id, :version, :width, :height, :format, :resource_type end base.after_create :remove_temporary_tag # In AR remote file deletion will be performed after transaction is committed base.after_commit :destroy_file, on: :destroy end |
Instance Method Details
#as_json(options = {}) ⇒ Object
13 14 15 |
# File 'lib/attachinary/orm/file_mixin.rb', line 13 def as_json( = {}) super(only: [:id, :public_id, :format, :version, :resource_type], methods: [:path]) end |
#fullpath(options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/attachinary/orm/file_mixin.rb', line 26 def fullpath(={}) format = .delete(:format) Cloudinary::Utils.cloudinary_url(path(format), .reverse_merge(:resource_type => resource_type)) end |
#path(custom_format = nil) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/attachinary/orm/file_mixin.rb', line 17 def path(custom_format=nil) p = "v#{version}/#{public_id}" if resource_type == 'image' && custom_format != false custom_format ||= format p<< ".#{custom_format}" end p end |