Module: Attachinary::FileMixin
- Included in:
- File
- Defined in:
- lib/attachinary/orm/file_mixin.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 |
# 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_destroy :destroy_file base.after_create :remove_temporary_tag end |
Instance Method Details
#as_json(options) ⇒ Object
12 13 14 |
# File 'lib/attachinary/orm/file_mixin.rb', line 12 def as_json() super(only: [:id, :public_id, :format, :version, :resource_type], methods: [:path]) end |
#fullpath(options = {}) ⇒ Object
25 26 27 28 |
# File 'lib/attachinary/orm/file_mixin.rb', line 25 def fullpath(={}) format = .delete(:format) Cloudinary::Utils.cloudinary_url(path(format), .reverse_merge(:resource_type => resource_type)) end |
#path(custom_format = nil) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/attachinary/orm/file_mixin.rb', line 16 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 |