Class: Resizor::AttachedResizorAsset
- Inherits:
-
ResizorAsset
- Object
- ResizorAsset
- Resizor::AttachedResizorAsset
- Defined in:
- lib/resizor/asset.rb
Instance Attribute Summary collapse
-
#attachment_name ⇒ Object
Returns the value of attribute attachment_name.
-
#file ⇒ Object
Returns the value of attribute file.
-
#instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from ResizorAsset
#height, #id, #mime_type, #name, #path, #size, #width
Instance Method Summary collapse
- #assign(in_file) ⇒ Object
- #clear ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
-
#initialize(attachment_name, instance, options = {}) ⇒ AttachedResizorAsset
constructor
A new instance of AttachedResizorAsset.
- #save ⇒ Object
Methods inherited from ResizorAsset
#resize_token_for, #save_to_resizor, #url
Constructor Details
#initialize(attachment_name, instance, options = {}) ⇒ AttachedResizorAsset
Returns a new instance of AttachedResizorAsset.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/resizor/asset.rb', line 75 def initialize(, instance, = {}) @attachment_name = @instance = instance @options = @id = instance_read("resizor_id") @name = instance_read("name") @mime_type = instance_read("mime_type") @size = instance_read("size") @width = instance_read("width") @height = instance_read("height") end |
Instance Attribute Details
#attachment_name ⇒ Object
Returns the value of attribute attachment_name.
73 74 75 |
# File 'lib/resizor/asset.rb', line 73 def @attachment_name end |
#file ⇒ Object
Returns the value of attribute file.
73 74 75 |
# File 'lib/resizor/asset.rb', line 73 def file @file end |
#instance ⇒ Object
Returns the value of attribute instance.
73 74 75 |
# File 'lib/resizor/asset.rb', line 73 def instance @instance end |
Instance Method Details
#assign(in_file) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/resizor/asset.rb', line 87 def assign in_file if in_file.is_a?(Resizor::ResizorAsset) @id = in_file.id @name = in_file.name @mime_type = in_file.mime_type @size = in_file.size @width = in_file.width @height = in_file.height else @file = in_file end end |
#clear ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/resizor/asset.rb', line 137 def clear @id = nil @name = nil @mime_type = nil @size = nil @width = nil @height = nil end |
#delete ⇒ Object
125 126 127 |
# File 'lib/resizor/asset.rb', line 125 def delete destroy end |
#destroy ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/resizor/asset.rb', line 129 def destroy if ret = super clear instance.send(:save) end ret end |
#save ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/resizor/asset.rb', line 100 def save if file @path = File.join(Dir.tmpdir, file.original_filename) if file.is_a?(Tempfile) || file.respond_to?(:path) FileUtils.move(file.path, @path) else File.open(@path, 'wb') { |f| f.write(file.read) } end if save_to_resizor File.unlink(@path) @file = nil else instance.errors[.to_sym] << "can't be saved" return false end end instance_write(:resizor_id, @id) instance_write(:name, @name) instance_write(:mime_type, @mime_type) instance_write(:size, @size) instance_write(:width, @width) instance_write(:height, @height) return true end |