Class: Admin::Image::S3
- Inherits:
-
Object
- Object
- Admin::Image::S3
- Includes:
- S3
- Defined in:
- lib/ecrire/app/models/admin/image.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #configuration_hash ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(options = {}) ⇒ S3
constructor
A new instance of S3.
- #service ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ S3
Returns a new instance of S3.
60 61 62 63 64 65 66 67 |
# File 'lib/ecrire/app/models/admin/image.rb', line 60 def initialize(={}) @errors = ActiveModel::Errors.new(self) @access_key = .fetch('access_key', "") @secret_key = .fetch('secret_key', "") @path = .fetch('path', "") @bucket = service.bucket(.fetch('bucket', 'ecrire')) end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
58 59 60 |
# File 'lib/ecrire/app/models/admin/image.rb', line 58 def access_key @access_key end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
58 59 60 |
# File 'lib/ecrire/app/models/admin/image.rb', line 58 def bucket @bucket end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
58 59 60 |
# File 'lib/ecrire/app/models/admin/image.rb', line 58 def errors @errors end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
58 59 60 |
# File 'lib/ecrire/app/models/admin/image.rb', line 58 def path @path end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
58 59 60 |
# File 'lib/ecrire/app/models/admin/image.rb', line 58 def secret_key @secret_key end |
Instance Method Details
#configuration_hash ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ecrire/app/models/admin/image.rb', line 69 def configuration_hash config = { 'access_key' => access_key, 'secret_key' => secret_key, 'bucket' => bucket.name } unless path.blank? config['path'] = path end config end |
#connect ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/ecrire/app/models/admin/image.rb', line 83 def connect begin @bucket.retrieve @connected = true rescue Error::ResponseError, ArgumentError, SocketError => e errors.add :remote, e end end |
#connected? ⇒ Boolean
99 100 101 102 103 104 |
# File 'lib/ecrire/app/models/admin/image.rb', line 99 def connected? if @connected.nil? connect end !!@connected end |
#service ⇒ Object
92 93 94 95 96 97 |
# File 'lib/ecrire/app/models/admin/image.rb', line 92 def service @service ||= Service.new(access_key_id: access_key, secret_access_key: secret_key, use_ssl: true ) end |