Permalink
Browse files

Merge pull request #1 from bozydar/master

Versions support added and fixed bug for model update.
  • Loading branch information...
2 parents dd46cf2 + 47072ad commit 12e3237dde3b8a0593e6bcb2bde2625cdf30ff3c @motske committed Jul 18, 2012
Showing with 39 additions and 2 deletions.
  1. +1 −1 carrierwave-riak.gemspec
  2. +38 −1 lib/carrierwave/uploader/riak.rb
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "carrierwave-riak"
- s.version = "0.1.0"
+ s.version = "0.1.1"
s.platform = Gem::Platform::RUBY
s.authors = ["Kevin Motschiedler"]
s.email = ["kdmotschiedler@gmail.com"]
@@ -13,11 +13,48 @@ class Riak < Base
after :store, :updatemodel
def updatemodel(file)
- if(model.read_attribute(:"#{self.mounted_as}").nil?)
+ if model.read_attribute(:"#{self.mounted_as}").nil? || model.read_attribute(:"#{self.mounted_as}") != self.key
model.update_attribute(:"#{self.mounted_as}", self.key)
end
end
end
+
+ private
+
+ def build_versioned_key(key, version_name)
+ unless version_name.nil?
+ "#{version_name}_#{key}"
+ else
+ key
+ end
+
+ end
+
+ def store_versions!(new_file)
+ active_versions.each { |name, v|
+ v.key = build_versioned_key(key, name)
+ v.store!(new_file)
+ }
+ end
+
+ def remove_versions!
+ versions.each { |name, v|
+ v.key = build_versioned_key(key, name)
+ v.remove!
+ }
+ end
+
+ def retrieve_versions_from_cache!(cache_name)
+ versions.each { |name, v|
+ v.key = build_versioned_key(key, name)
+ v.retrieve_from_cache!(cache_name)
+ }
+ end
+
+ def retrieve_versions_from_store!(identifier)
+ versions.each { |name, v|
+ v.retrieve_from_store!(build_versioned_key(identifier, name)) }
+ end
end
end
end

0 comments on commit 12e3237

Please sign in to comment.