Module: SimplyStored::Storage::ClassMethods
- Included in:
- Couch::ClassMethods
- Defined in:
- lib/simply_stored/storage.rb
Instance Method Summary collapse
Instance Method Details
#define_attachment_accessors(name) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/simply_stored/storage.rb', line 121 def (name) define_method(name) do unless @_s3_attachments and @_s3_attachments[name] @_s3_attachments = {name => {}} @_s3_attachments[name][:value] = s3_bucket(name).get((name)) end @_s3_attachments[name][:value] end define_method("#{name}=") do |value| @_s3_attachments ||= {} @_s3_attachments[name] ||= {} @_s3_attachments[name].update(:value => value, :dirty => true) value end define_method("#{name}_url") do if [name][:permissions] == 'private' RightAws::S3Generator.new([name][:access_key], [name][:secret_access_key], :multi_thread => true, :ca_file => [name][:ca_file]).bucket([name][:bucket]).get((name), 5.minutes) else "http://#{[name][:bucket].to_s}.s3.amazonaws.com/#{(name)}" end end end |
#has_s3_attachment(name, options = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/simply_stored/storage.rb', line 87 def (name, = {}) require 'right_aws' name = name.to_sym self.class.instance_eval do attr_accessor :_s3_options end self.class_eval do if respond_to?(:property) property "#{name}_size" else simpledb_integer "#{name}_size" end end raise ArgumentError, "No bucket name specified for attachment #{name}" if [:bucket].blank? = { :permissions => 'private', :ssl => true, :location => :us, # use :eu for European buckets :ca_file => nil, # point to CA file for SSL certificate verification :after_delete => :nothing, # or :delete to delete the item on S3 after it is deleted in the DB, :logger => nil # use the default RightAws logger (stdout) }.update() self. ||= {} self.[name] = (name) attr_reader :_s3_attachments include InstanceMethods end |