cloud_tempfile 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -11,10 +11,9 @@ before_install:
11
11
  - gem install bundler
12
12
  env:
13
13
  global:
14
- # - FOG_DIRECTORY=asset-sync-travis
15
- # - FOG_PROVIDER=AWS
16
- # - secure: "dy8Fqlg3b1ZMK1BY5z6NMQLbzAVd7GWVYY0MeCQALz76zRac0z8MyU8hkv6h\nozFry7DSdbGehGT9foOnkWTwzGzf1rzdd5cmWrUPk1wDTRgMM9SrwodPj1TU\nzsq2EFx0a79vADQN8JXkpLC1YD6kEb9aWkTxrIT9KBgw+J5H32o="
17
- # - secure: "Hmx7D7/p2LlA2ya/xBIz21s/8MLIQCjvfYB7RWBNlWk1PfqRLAz8wX6TUVWy\nfAFktMjLnpRLRYO7AgQS4jcfQ/k0HYK9IXzqXzeI00TNm0Vwp0TCXhawiOFT\nSvUMhs2/1vRfjN0HOJ75XlWRhJzV/G5rOMiafAZLsVzN/0iiB8g="
14
+ addons:
15
+ code_climate:
16
+ repo_token: 08219ed943b69ed2db93fc18ecd00f72f6dabc4cdb9792e22a731c0ff2c2b818
18
17
  matrix:
19
18
  include:
20
19
  - rvm: 1.9.3
data/CHANGELOG.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # RELEASE HISTORY
2
2
 
3
- ## v0.0.1 / 2014-02-16
3
+ ## v0.0.2 / 2014-03-13
4
4
 
5
- Version 0.0.1 (Kevin Bolduc)
5
+ Version 0.0.2 (Kevin Bolduc)
6
6
 
7
7
  Changes:
8
+ * #1 Add Code Climate metric reporting support
9
+ * #2 Allow the option to override the expiry when uploading a file to the Cloud
10
+
11
+ ## v0.0.1 / 2014-03-12
8
12
 
13
+ Version 0.0.1 (Kevin Bolduc)
14
+
15
+ Changes:
16
+ * v0.0.1 CloudTempfile
17
+ * Updated README.md
9
18
  * Initial commit
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
1
  [![Build Status](https://secure.travis-ci.org/kbolduc/cloud_tempfile.png)](http://travis-ci.org/kbolduc/cloud_tempfile)
2
+ [![Dependency Status](https://gemnasium.com/kbolduc/cloud_tempfile.png)](https://gemnasium.com/kbolduc/cloud_tempfile)
3
+ [![Code Climate](https://codeclimate.com/github/kbolduc/cloud_tempfile.png)](https://codeclimate.com/github/kbolduc/cloud_tempfile)
4
+ [![Coverage Status](https://coveralls.io/repos/kbolduc/cloud_tempfile/badge.png?branch=master)](https://coveralls.io/r/kbolduc/cloud_tempfile?branch=master)
5
+ [![Gem Version](https://badge.fury.io/rb/cloud_tempfile.png)](http://badge.fury.io/rb/cloud_tempfile)
6
+ [![Gittip](http://img.shields.io/gittip/kbolduc.png)](https://www.gittip.com/kbolduc/)
2
7
 
3
8
  # CloudTempfile
4
9
 
@@ -86,6 +91,7 @@ The generator will create a Rails initializer at `config/initializers/cloud_temp
86
91
 
87
92
  ``` ruby
88
93
  CloudTempfile.configure do |config|
94
+ config.enabled = true
89
95
  config.fog_provider = 'AWS'
90
96
  config.fog_directory = ENV['FOG_DIRECTORY']
91
97
  config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
@@ -110,6 +116,7 @@ The generator will create a YAML file at `config/cloud_tempfile.yml`.
110
116
 
111
117
  ``` yaml
112
118
  defaults: &defaults
119
+ enabled: true
113
120
  fog_provider: "AWS"
114
121
  fog_directory: "rails-app-assets"
115
122
  aws_access_key_id: "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
@@ -122,9 +129,11 @@ defaults: &defaults
122
129
 
123
130
  development:
124
131
  <<: *defaults
132
+ enabled: false
125
133
 
126
134
  test:
127
135
  <<: *defaults
136
+ enabled: false
128
137
 
129
138
  production:
130
139
  <<: *defaults
@@ -140,7 +149,8 @@ CloudTempfile.config.fog_provider == ENV['FOG_PROVIDER']
140
149
 
141
150
  #### CloudTempfile (optional)
142
151
 
143
- * **enabled**: (`true, false`) when false, will disable CloudTempfile and local Tempfile will be created instead. **default:** `'true'` (enabled)
152
+ * **enabled**: (`true, false`) when false, will disable CloudTempfile and local Tempfile will be created instead.
153
+ * **default:** `'false'` (disabled)
144
154
 
145
155
  #### Fog (Required)
146
156
  * **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage)
@@ -193,27 +203,17 @@ production:
193
203
  fog_region: 'eu-west-1'
194
204
  ```
195
205
 
196
- ## Fail Silently
197
-
198
- With the `fail_silently` option enabled, when running `rake assets:precompile` CloudTempfile will never throw an error due to missing configuration variables.
199
-
200
- With the new **user_env_compile** feature of Heroku (see above), this is no longer required or recommended. Yet was added for the following reasons:
201
-
202
- > With Rails 3.1 on the Heroku cedar stack, the deployment process automatically runs `rake assets:precompile`. If you are using **ENV** variable style configuration. Due to the methods with which Heroku compile slugs, there will be an error raised by asset\_sync as the environment is not available. This causes heroku to install the `rails31_enable_runtime_asset_compilation` plugin which is not necessary when using **cloud_tempfile** and also massively slows down the first incoming requests to your app.
203
-
204
- > To prevent this part of the deploy from failing (cloud_tempfile raising a config error), but carry on as normal set `fail_silently` to true in your configuration and ensure to run `heroku run rake assets:precompile` after deploy.
205
-
206
206
  ## Rake Task
207
207
 
208
208
  A rake task is included within the **cloud_tempfile** gem to perform the clean up:
209
209
 
210
210
  ``` ruby
211
- namespace :cloud_tempfile do
212
- desc "Synchronize assets to S3"
213
- task :sync => :environment do
214
- CloudTempfile.sync
211
+ namespace :cloud_tempfile do
212
+ desc "Clean up expired temp files from the remote storage"
213
+ task :clear => :environment do
214
+ CloudTempfile.clear
215
+ end
215
216
  end
216
- end
217
217
  ```
218
218
 
219
219
  ## Todo
@@ -7,17 +7,17 @@ require "cloud_tempfile/version"
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "cloud_tempfile"
9
9
  s.version = CloudTempfile::VERSION
10
- s.date = "2014-02-16"
10
+ s.date = "2014-03-13"
11
11
  s.platform = Gem::Platform::RUBY
12
12
  s.authors = ["Kevin Bolduc"]
13
13
  s.email = ["kevin.bolduc@gmail.com"]
14
- s.homepage = "https://github.com/kbolduc/CloudTempfile"
14
+ s.homepage = "http://github.com/kbolduc/cloud_tempfile"
15
15
  s.summary = %q{Tempfile creation directly on cloud storage (S3, Google, Rackspace etc] which can be utilized in a Ruby application}
16
- s.description = %q{Save any CloudTempfile object and it will be directly persisted to the cloud!}
16
+ s.description = %q{Tempfile creation directly on cloud storage (S3, Google, Rackspace etc] which can be utilized in a Ruby application}
17
17
  s.license = 'MIT'
18
18
 
19
19
  # rubyforge
20
- #s.rubyforge_project = "cloud_tempfile"
20
+ s.rubyforge_project = "cloud_tempfile"
21
21
 
22
22
  s.add_dependency('fog', ">= 1.8.0")
23
23
  s.add_dependency('activemodel')
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rcov", :platforms=>:mri_18, :group=>[:development, :test]
5
+ gem 'rcov', :platforms => :mri_18, :group => [:development, :test]
6
6
  gem "simplecov", :platforms=>[:jruby, :mri_19, :ruby_19, :mri_20, :rbx], :group=>[:development, :test], :require=>false
7
7
  gem "jruby-openssl", :platform=>:jruby
8
8
  gem "rails", "~> 3.1.0"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rcov", :platforms=>:mri_18, :group=>[:development, :test]
5
+ gem 'rcov', :platforms => :mri_18, :group => [:development, :test]
6
6
  gem "simplecov", :platforms=>[:jruby, :mri_19, :ruby_19, :mri_20, :rbx], :group=>[:development, :test], :require=>false
7
7
  gem "jruby-openssl", :platform=>:jruby
8
8
  gem "rails", "~> 3.2.0"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rcov", :platforms=>:mri_18, :group=>[:development, :test]
5
+ gem 'rcov', :platforms => :mri_18, :group => [:development, :test]
6
6
  gem "simplecov", :platforms=>[:jruby, :mri_19, :ruby_19, :mri_20, :rbx], :group=>[:development, :test], :require=>false
7
7
  gem "jruby-openssl", :platform=>:jruby
8
8
  gem "rails", "~> 4.0.0"
@@ -42,6 +42,7 @@ module CloudTempfile
42
42
  # == Options
43
43
  # [:+file_name+:] The file name to use for the Tempfile
44
44
  # [:+file_raw_data+:] The raw file data to be persisted
45
+ # [:+expiry+:] The expiry is the number of seconds the file will available publicly
45
46
  #
46
47
  # @param [Hash] options The Hash of options
47
48
  # @return [File]
@@ -53,9 +54,9 @@ module CloudTempfile
53
54
 
54
55
  with_config do
55
56
  if !(config && config.local?)
56
- return self.storage.upload_file(_file_name, _file_raw_data)
57
+ return self.storage.upload_file(_file_name, _file_raw_data, options)
57
58
  else
58
- return self.storage.local_file(_file_name, _file_raw_data)
59
+ return self.storage.local_file(_file_name, _file_raw_data, options)
59
60
  end
60
61
  end
61
62
  end
@@ -57,12 +57,13 @@ module CloudTempfile
57
57
 
58
58
  self.public = false
59
59
  self.prefix = "tmp/"
60
+ self.expiry = 600 # 10 Min = 600 Seconds
60
61
 
61
62
  self.fail_silently = false
62
63
  self.log_silently = true
63
64
 
64
65
  self.clean_up = false
65
- self.clean_up_older_than = 600
66
+ self.clean_up_older_than = 86400 # 1 Day = 86400 Seconds
66
67
 
67
68
  load_yml! if defined?(Rails) && yml_exists?
68
69
  end
@@ -26,7 +26,7 @@ module CloudTempfile
26
26
  @directory ||= connection.directories.get(self.config.fog_directory, :prefix => prefix)
27
27
  end
28
28
 
29
- # This action will upload a AWS::File to the specified directory
29
+ # This action will upload a Fog::Storage::File to the specified directory
30
30
  # @return [Fog::Storage::File]
31
31
  def upload_file(f, body, options={})
32
32
  file = init_fog_file(f, body, options)
@@ -99,7 +99,7 @@ module CloudTempfile
99
99
 
100
100
  aws_acl = (self.config.aws_acl?)? self.config.aws_access_control_list.to_s : nil
101
101
  # expiry is the number of seconds the file will available publicly
102
- expiry = (self.config.expiry?)? self.config.expiry.to_i : nil
102
+ expiry = options.has_key?(:expiry)? options[:expiry] : ((self.config.expiry?)? self.config.expiry.to_i : nil)
103
103
  ext = File.extname(filename)[1..-1] # The file extension
104
104
  mime = MultiMime.lookup(ext) # Look up the content type based off the file extension
105
105
  prefix = options.has_key?(:prefix)? options[:prefix] : self.config.prefix
@@ -5,5 +5,5 @@
5
5
  # Time:: 3:23 PM
6
6
 
7
7
  module CloudTempfile
8
- VERSION = "0.0.1"
8
+ VERSION = "0.0.2"
9
9
  end
@@ -185,7 +185,7 @@ describe CloudTempfile::Storage do
185
185
  end
186
186
 
187
187
  file = @storage.upload_file(filename, file)
188
- file.public_url.should be_nil if !@mock
188
+ file.public_url.should_not be_nil if !@mock
189
189
  end
190
190
 
191
191
  it 'has private visibility and expiry' do
@@ -207,7 +207,81 @@ describe CloudTempfile::Storage do
207
207
  end
208
208
 
209
209
  file = @storage.upload_file(filename, file)
210
- file.public_url.should_not be_nil if !@mock
210
+ if !@mock
211
+ file.should_not be_nil
212
+ file.public_url.should_not be_nil
213
+ file.public_url.should include((Time.now.utc.to_i + @config.expiry).to_s.chop.chop)
214
+ end
215
+ end
216
+ end
217
+
218
+ describe 'AWS#upload_file with CloudTempfile private', :ignore => false do
219
+ before(:each) do
220
+ @config = CloudTempfile::Config.new
221
+ @config.enabled = true
222
+ @config.fog_provider = "AWS"
223
+ @config.aws_access_key_id = !@mock? ENV['AWS_ACCESS_KEY_ID'] : 'KEY'
224
+ @config.aws_secret_access_key = !@mock? ENV['AWS_SECRET_ACCESS_KEY'] : 'SECRET_KEY'
225
+ @config.fog_directory = !@mock? ENV['FOG_DIRECTORY'] : 'bucket'
226
+ @config.prefix = "tmp-test/"
227
+ @config.public = false
228
+ @config.expiry = 60
229
+
230
+ #Enable/Disable Fog mocking by enivronment variables for testing
231
+ @mock = ((ENV['RSPEC_MOCK'].nil?)? ((ENV['AWS_ACCESS_KEY_ID'].nil?)? true : ENV['AWS_ACCESS_KEY_ID']) : ENV['RSPEC_MOCK']=='true')
232
+ Fog.mock! if @mock
233
+
234
+ @storage = CloudTempfile::Storage.new(@config)
235
+ end
236
+
237
+ after(:each) do
238
+ Fog.unmock! if @mock
239
+ end
240
+
241
+
242
+ it 'should have the expiry set when private' do
243
+ filename = 'TEST.pdf'
244
+ file = File.open(File.dirname(__FILE__) + '/../fixtures/assets/' + filename)
245
+
246
+ if @mock
247
+ directory = double
248
+ files = double
249
+
250
+ @storage.stub(:directory).and_return(directory)
251
+ directory.stub(:files).and_return(files)
252
+
253
+ files.should_receive(:create)
254
+ end
255
+
256
+ file = @storage.upload_file(filename, file)
257
+ if !@mock
258
+ file.should_not be_nil
259
+ file.public_url.should_not be_nil
260
+ file.public_url.should include((Time.now.utc.to_i + @config.expiry).to_s.chop.chop)
261
+ end
262
+ end
263
+
264
+ it 'should accept the option to override the expiry when private' do
265
+ filename = 'TEST.pdf'
266
+ file = File.open(File.dirname(__FILE__) + '/../fixtures/assets/' + filename)
267
+
268
+ if @mock
269
+ directory = double
270
+ files = double
271
+
272
+ @storage.stub(:directory).and_return(directory)
273
+ directory.stub(:files).and_return(files)
274
+
275
+ files.should_receive(:create)
276
+ end
277
+
278
+ expiry = 1000
279
+ file = @storage.upload_file(filename, file, :expiry => expiry)
280
+ if !@mock
281
+ file.should_not be_nil
282
+ file.public_url.should_not be_nil
283
+ file.public_url.should include((Time.now.utc.to_i + expiry).to_s.chop.chop)
284
+ end
211
285
  end
212
286
  end
213
287
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_tempfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-16 00:00:00.000000000 Z
12
+ date: 2014-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
16
- requirement: &70340592492360 !ruby/object:Gem::Requirement
16
+ requirement: &70192949525660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70340592492360
24
+ version_requirements: *70192949525660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &70340592491920 !ruby/object:Gem::Requirement
27
+ requirement: &70192949525220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70340592491920
35
+ version_requirements: *70192949525220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70340592491460 !ruby/object:Gem::Requirement
38
+ requirement: &70192949524720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70340592491460
46
+ version_requirements: *70192949524720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70340592491020 !ruby/object:Gem::Requirement
49
+ requirement: &70192949524280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70340592491020
57
+ version_requirements: *70192949524280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70340592490600 !ruby/object:Gem::Requirement
60
+ requirement: &70192949540200 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70340592490600
68
+ version_requirements: *70192949540200
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cloud_tempfile
71
- requirement: &70340592490180 !ruby/object:Gem::Requirement
71
+ requirement: &70192949539780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70340592490180
79
+ version_requirements: *70192949539780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: appraisal
82
- requirement: &70340592489740 !ruby/object:Gem::Requirement
82
+ requirement: &70192949539360 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,9 +87,9 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70340592489740
91
- description: Save any CloudTempfile object and it will be directly persisted to the
92
- cloud!
90
+ version_requirements: *70192949539360
91
+ description: Tempfile creation directly on cloud storage (S3, Google, Rackspace etc]
92
+ which can be utilized in a Ruby application
93
93
  email:
94
94
  - kevin.bolduc@gmail.com
95
95
  executables: []
@@ -138,7 +138,7 @@ files:
138
138
  - spec/unit/multi_mime_spec.rb
139
139
  - spec/unit/railsless_spec.rb
140
140
  - spec/unit/storage_spec.rb
141
- homepage: https://github.com/kbolduc/CloudTempfile
141
+ homepage: http://github.com/kbolduc/cloud_tempfile
142
142
  licenses:
143
143
  - MIT
144
144
  post_install_message:
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  segments:
155
155
  - 0
156
- hash: -2077317929667888868
156
+ hash: 2622981772994909634
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  none: false
159
159
  requirements:
@@ -162,9 +162,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: -2077317929667888868
165
+ hash: 2622981772994909634
166
166
  requirements: []
167
- rubyforge_project:
167
+ rubyforge_project: cloud_tempfile
168
168
  rubygems_version: 1.8.10
169
169
  signing_key:
170
170
  specification_version: 3