Module: SimplyStored::Storage::InstanceMethods
- Defined in:
- lib/simply_stored/storage.rb
Instance Method Summary collapse
- #_s3_options ⇒ Object
- #delete(*args) ⇒ Object
- #delete_attachments ⇒ Object
- #destroy(*args) ⇒ Object
- #s3_attachment_key(name) ⇒ Object
- #s3_bucket(name) ⇒ Object
- #s3_connection(name) ⇒ Object
- #save(validate = true) ⇒ Object
- #save!(*args) ⇒ Object
- #save_attachments ⇒ Object
- #update_attachment_sizes ⇒ Object
Instance Method Details
#_s3_options ⇒ Object
4 5 6 |
# File 'lib/simply_stored/storage.rb', line 4 def self.class. end |
#delete(*args) ⇒ Object
37 38 39 40 |
# File 'lib/simply_stored/storage.rb', line 37 def delete(*args) super end |
#delete_attachments ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/simply_stored/storage.rb', line 60 def return unless id.present? (@_s3_attachments || {}).each do |name, | if [name][:after_delete] == :delete key = s3_bucket(name).key((name), true) key.delete end end end |
#destroy(*args) ⇒ Object
42 43 44 45 |
# File 'lib/simply_stored/storage.rb', line 42 def destroy(*args) super end |
#s3_attachment_key(name) ⇒ Object
81 82 83 |
# File 'lib/simply_stored/storage.rb', line 81 def (name) "#{self.class.name.tableize}/#{name}/#{id}" end |
#s3_bucket(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/simply_stored/storage.rb', line 12 def s3_bucket(name) if !@_s3_bucket @_s3_bucket = s3_connection(name).bucket([name][:bucket]) location = ([name][:location] == :eu) ? :eu : nil @_s3_bucket = s3_connection(name).bucket([name][:bucket], true, [name][:permissions], :location => location) if @_s3_bucket.nil? end @_s3_bucket rescue Exception => e raise ArgumentError, "Could not access/create S3 bucket '#{name}': #{e} #{e.backtrace.join("\n")}" end |
#s3_connection(name) ⇒ Object
8 9 10 |
# File 'lib/simply_stored/storage.rb', line 8 def s3_connection(name) @_s3_connection ||= RightAws::S3.new([name][:access_key], [name][:secret_access_key], :multi_thread => true, :ca_file => [name][:ca_file], :logger => [name][:logger]) end |
#save(validate = true) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/simply_stored/storage.rb', line 23 def save(validate = true) if ret = super(validate) end ret end |
#save!(*args) ⇒ Object
31 32 33 34 35 |
# File 'lib/simply_stored/storage.rb', line 31 def save!(*args) super end |
#save_attachments ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/simply_stored/storage.rb', line 47 def return unless id.present? if @_s3_attachments @_s3_attachments.each do |name, | if [:dirty] value = [:value].is_a?(String) ? [:value] : [:value].to_json s3_bucket(name).put((name), value, {}, [name][:permissions]) [:dirty] = false end end end end |
#update_attachment_sizes ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/simply_stored/storage.rb', line 70 def if @_s3_attachments @_s3_attachments.each do |name, | if [:dirty] value = [:value].is_a?(String) ? [:value] : [:value].to_json send("#{name}_size=", (value.size rescue nil)) end end end end |