spree_s3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Thoughtful, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ module S3
2
+ class << self
3
+ attr_accessor :key, :secret, :bucket
4
+
5
+ def key
6
+ @key || ENV['S3_KEY']
7
+ end
8
+
9
+ def secret
10
+ @secret || ENV['S3_SECRET']
11
+ end
12
+
13
+ def bucket
14
+ @bucket || ENV['S3_BUCKET']
15
+ end
16
+
17
+ def enabled?
18
+ true unless key.blank? or secret.blank? or bucket.blank?
19
+ end
20
+
21
+ def load_s3_yaml
22
+ path = File.join(::Rails.root, 'config', 's3.yml')
23
+ file = File.read(path) if File.exist? path
24
+ if file
25
+ yaml = YAML.load(ERB.new(file).result)[::Rails.env]
26
+ load_s3_config yaml.with_indifferent_access if yaml
27
+ end
28
+ end
29
+
30
+ def load_s3_config(hash)
31
+ self.key = hash[:key]
32
+ self.secret = hash[:secret]
33
+ self.bucket = hash[:bucket]
34
+ end
35
+ end
36
+
37
+ module Attachment
38
+ def sends_files_to_s3
39
+ [:attachment, :icon].each do |type|
40
+ definition = self.attachment_definitions[type]
41
+ configure_definition_for_s3(definition) if definition
42
+ end
43
+ end
44
+
45
+ private
46
+ def configure_definition_for_s3(definition)
47
+ definition.delete :url
48
+ definition[:path] = definition[:path].gsub(':rails_root/public/', '')
49
+ definition[:storage] = 's3'
50
+ definition[:bucket] = S3.bucket
51
+ definition[:s3_credentials] = {:access_key_id => S3.key, :secret_access_key => S3.secret}
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,26 @@
1
+ require 'spree_core'
2
+ require 'spree_s3_hooks'
3
+
4
+ module SpreeS3
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ S3.load_s3_yaml
11
+
12
+ Image.class_eval do
13
+ extend S3::Attachment
14
+ sends_files_to_s3 if S3.enabled?
15
+ end
16
+
17
+ # FIXME: causing problems during db:migrate
18
+ # Taxon.class_eval do
19
+ # extend S3::Attachment
20
+ # sends_files_to_s3 if S3.enabled?
21
+ # end
22
+ end
23
+
24
+ config.to_prepare &method(:activate).to_proc
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeS3Hooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,26 @@
1
+ namespace :spree_s3 do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_s3:install:migrations'].invoke
5
+ Rake::Task['spree_s3:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
14
+ Spree::FileUtilz.mirror_files(source, destination)
15
+ end
16
+
17
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
18
+ task :assets do
19
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
20
+ destination = File.join(Rails.root, 'public')
21
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
22
+ Spree::FileUtilz.mirror_files(source, destination)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dylan Meissner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.30.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.30.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: paperclip
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.3.6
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.6
46
+ - !ruby/object:Gem::Dependency
47
+ name: aws-s3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.6.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.2
62
+ description: Amazon S3 integration for your Spree store, using the aws-s3 gem.
63
+ email:
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE
69
+ - lib/s3.rb
70
+ - lib/spree_s3.rb
71
+ - lib/spree_s3_hooks.rb
72
+ - lib/tasks/install.rake
73
+ - lib/tasks/spree_s3.rake
74
+ homepage:
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.7
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements:
93
+ - none
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.24
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Amazon S3 integration for Spree
99
+ test_files: []