carrierwave-ripple 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tyler Hunt
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,22 @@
1
+ # CarrierWave for Ripple
2
+
3
+ This gem adds support for Ripple to [CarrierWave][].
4
+
5
+ [CarrierWave]: https://github.com/jnicklas/carrierwave
6
+
7
+ ## Installation
8
+
9
+ gem install carrierwave-ripple
10
+
11
+ ## Requiring the gem
12
+
13
+ require 'carrierwave/ripple'
14
+
15
+ ## Using Bundler
16
+
17
+ gem 'carrierwave-ripple', :require => 'carrierwave/ripple'
18
+
19
+ ## License
20
+
21
+ CarrierWave for Ripple is Copyright © 2011 Tyler Hunt. It is free software, and
22
+ may be redistributed under the terms specified in the LICENSE file.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,18 @@
1
+ require './lib/carrierwave/ripple/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'carrierwave-ripple'
5
+ s.version = Carrierwave::Ripple::VERSION
6
+ s.authors = ['Tyler Hunt']
7
+ s.email = ['tyler@tylerhunt.com']
8
+ s.homepage = 'https://github.com/tylerhunt/carrierwave-ripple'
9
+ s.summary = %q{Ripple support for CarrierWave}
10
+ s.description = %q{Ripple support for CarrierWave}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ['lib']
16
+
17
+ s.add_runtime_dependency 'carrierwave'
18
+ end
@@ -0,0 +1,49 @@
1
+ require 'carrierwave/ripple/version'
2
+ require 'carrierwave/validations/active_model'
3
+ require 'ripple/document'
4
+
5
+ module CarrierWave
6
+ module Ripple
7
+ include CarrierWave::Mount
8
+
9
+ def mount_uploader(column, uploader=nil, options={}, &block)
10
+ property column, String
11
+
12
+ super
13
+
14
+ alias_method :read_uploader, :[]
15
+ alias_method :write_uploader, :[]=
16
+
17
+ include CarrierWave::Validations::ActiveModel
18
+
19
+ if uploader_option(column.to_sym, :validate_integrity)
20
+ validates_integrity_of column
21
+ end
22
+
23
+ if uploader_option(column.to_sym, :validate_processing)
24
+ validates_processing_of column
25
+ end
26
+
27
+ after_save :"store_#{column}!"
28
+ before_save :"write_#{column}_identifier"
29
+ after_destroy :"remove_#{column}!"
30
+ before_update :"store_previous_model_for_#{column}"
31
+ after_save :"remove_previously_stored_#{column}"
32
+
33
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
34
+ def #{column}=(new_file)
35
+ column = _mounter(:#{column}).serialization_column
36
+
37
+ if new_file.is_a?(String)
38
+ write_uploader(column, new_file)
39
+ else
40
+ send(:"\#{column}_will_change!")
41
+ super
42
+ end
43
+ end
44
+ RUBY
45
+ end
46
+ end
47
+ end
48
+
49
+ Ripple::Document::ClassMethods.send(:include, CarrierWave::Ripple)
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module Ripple
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,79 @@
1
+ module CarrierWave
2
+ module Storage
3
+ class Riak < Abstract
4
+ class File
5
+ attr_reader :path
6
+
7
+ def initialize(uploader, path)
8
+ @uploader = uploader
9
+ @path = path
10
+ end
11
+
12
+ def write(file)
13
+ robject = bucket.new(key)
14
+ robject.content_type = file.content_type
15
+ robject.raw_data = file.read
16
+ robject.store
17
+ end
18
+
19
+ def read
20
+ @read ||= robject.raw_data
21
+ end
22
+
23
+ def delete
24
+ robject.delete
25
+ end
26
+
27
+ def content_type
28
+ robject.content_type
29
+ end
30
+
31
+ def size
32
+ read.length
33
+ end
34
+
35
+ def url
36
+ robject.url
37
+ end
38
+
39
+ def riak
40
+ @uploader.riak_client
41
+ end
42
+ private :riak
43
+
44
+ def bucket
45
+ riak.bucket(@uploader.riak_bucket_name)
46
+ end
47
+ private :bucket
48
+
49
+ def key
50
+ CGI.escape(path)
51
+ end
52
+ private :key
53
+
54
+ def robject
55
+ @robject ||= bucket.get(key)
56
+ end
57
+ private :robject
58
+ end
59
+
60
+ def store!(file)
61
+ File.new(uploader, uploader.store_path).tap do |stored|
62
+ stored.write(file)
63
+ end
64
+ end
65
+
66
+ def retrieve!(identifier)
67
+ File.new(uploader, uploader.store_path(identifier))
68
+ end
69
+ end
70
+ end
71
+
72
+ Uploader::Base.add_config :riak_client
73
+ Uploader::Base.add_config :riak_bucket_name
74
+
75
+ configure do |config|
76
+ config.storage_engines[:riak] = 'CarrierWave::Storage::Riak'
77
+ config.riak_bucket_name = 'uploads'
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-ripple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tyler Hunt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: carrierwave
16
+ requirement: &70326873352360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70326873352360
25
+ description: Ripple support for CarrierWave
26
+ email:
27
+ - tyler@tylerhunt.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - carrierwave-ripple.gemspec
38
+ - lib/carrierwave/ripple.rb
39
+ - lib/carrierwave/ripple/version.rb
40
+ - lib/carrierwave/storage/riak.rb
41
+ homepage: https://github.com/tylerhunt/carrierwave-ripple
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.6
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Ripple support for CarrierWave
65
+ test_files: []