carrierwave-raca 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a66bc60c6d86021cbad1a359e76222ce727a0e0
4
+ data.tar.gz: 56c328e1953f56df51d44edd66a2e36913179152
5
+ SHA512:
6
+ metadata.gz: 736b93619a1184cc7115fe4dfe35c519ab0190e9e038ba660b6d7fe9826b3d20925eb884346c05488ebd0ae4f928943f337e7b94dc0d7881e606f8c5b607a563
7
+ data.tar.gz: 2c3d878cf088ec768f4af1c2dadabf5ea025aeca1e2c16cd6d0303fcea2a6417748b33604c5b40a08b0aa6c2354846f9e0c7ee2a23bc1186760bb1a8b10e5c0c
data/README.markdown ADDED
@@ -0,0 +1,25 @@
1
+ # carrierwave-raca
2
+
3
+ Store carrierwave files on Rackspace Cloud Files using the raca gem.
4
+ [raca](http://rubygems.org/gems/raca) is lightweight, rackspace-only alternative
5
+ to fog.
6
+
7
+ ## Usage
8
+
9
+ Add this gem to your Gemfile:
10
+
11
+ gem 'carrierwave-raca'
12
+
13
+ ... and then modify config/environments/development.rb to add this at the bottom:
14
+
15
+ CarrierWave.configure do |config|
16
+ config.storage = :raca
17
+ config.asset_host = "https://somehost.rackcdn.com"
18
+ config.raca_username = "rackspace username"
19
+ config.raca_api_key = "rackspace api_key"
20
+ config.raca_container = "rackspace container name"
21
+ config.raca_region = :ord # or :syd, :dfw, :iad, :hkg
22
+ end
23
+
24
+ Depending on your intended setup, you might also need to add similar configuration
25
+ into other environments.
@@ -0,0 +1,111 @@
1
+ require 'raca'
2
+
3
+ module CarrierWave
4
+ module Storage
5
+ class Raca < Abstract
6
+
7
+ def store!(file)
8
+ File.new(uploader, connection, uploader.store_path).tap do |raca_file|
9
+ raca_file.store(file)
10
+ end
11
+ end
12
+
13
+ def retrieve!(identifier)
14
+ File.new(uploader, connection, uploader.store_path(identifier))
15
+ end
16
+
17
+ def connection
18
+ @connection ||= ::Raca::Account.new(uploader.raca_username, uploader.raca_api_key)
19
+ end
20
+
21
+ class File
22
+ attr_writer :content_type
23
+ attr_reader :uploader, :account, :path
24
+
25
+ def initialize(uploader, account, path)
26
+ @uploader = uploader
27
+ @account = account
28
+ @path = path
29
+ end
30
+
31
+ # is this required?
32
+ def attributes
33
+ object_metadata
34
+ end
35
+
36
+ def content_type
37
+ @content_type || object_metadata[:content_type]
38
+ end
39
+
40
+ def delete
41
+ container.delete(path)
42
+ end
43
+
44
+ def extension
45
+ path.split('.').last
46
+ end
47
+
48
+ def exists?
49
+ object_metadata != nil
50
+ end
51
+
52
+ def filename(options = {})
53
+ if file_url = url(options)
54
+ file_url.gsub(/.*\/(.*?$)/, '\1')
55
+ end
56
+ end
57
+
58
+ def read
59
+ tempfile = Tempfile.new("carrierwave-raca")
60
+ tempfile.close
61
+ container.download(path, tempfile.path)
62
+ ::File.read(tempfile.path)
63
+ ensure
64
+ tempfile.unlink if tempfile
65
+ end
66
+
67
+ def size
68
+ object_metadata[:bytes]
69
+ end
70
+
71
+ def store(new_file)
72
+ container.upload(path, new_file.file, "Content-Type" => new_file.content_type)
73
+ end
74
+
75
+ def to_file
76
+ # is this needed?
77
+ end
78
+
79
+ def url(options = {})
80
+ if uploader.asset_host
81
+ "#{uploader.asset_host}/#{path}"
82
+ else
83
+ path
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def authenticated_url
90
+ # is this needed?
91
+ end
92
+
93
+ def public_url
94
+ # is this needed?
95
+ end
96
+
97
+ def containers
98
+ @containers ||= account.containers(uploader.raca_region)
99
+ end
100
+
101
+ def container
102
+ @bucket ||= containers.get(uploader.raca_container)
103
+ end
104
+
105
+ def object_metadata
106
+ @object_metadata ||= container.object_metadata(path)
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,13 @@
1
+ require 'carrierwave'
2
+ require 'carrierwave/storage/raca'
3
+
4
+ class CarrierWave::Uploader::Base
5
+ add_config :raca_username
6
+ add_config :raca_api_key
7
+ add_config :raca_region
8
+ add_config :raca_container
9
+
10
+ configure do |config|
11
+ config.storage_engines[:raca] = 'CarrierWave::Storage::Raca'
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-raca
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Healy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: raca
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.14'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description: Use raca for Rackspace cloud files support in CarrierWave
76
+ email:
77
+ - james.healy@thecovnersation.edu.au
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - README.markdown
83
+ - lib/carrierwave-raca.rb
84
+ - lib/carrierwave/storage/raca.rb
85
+ homepage: https://github.com/conversation/carrierwave-raca
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: A slimmer alternative to using Fog for Cloud files support in CarrierWave
108
+ test_files: []
109
+ has_rdoc: