Permalink
Browse files

add carrierwave as submodule

we need the current master branch to use fog
  • Loading branch information...
1 parent be3a384 commit 7442cfa22527cbb2359a00ec27590187fb847934 @xithan xithan committed Aug 24, 2016
View
@@ -5,3 +5,6 @@
[submodule "tmpsets"]
path = card/tmpsets
url = https://github.com/wagn/decko-tmpsets.git
+[submodule "card/vendor/carrierwave"]
+ path = card/vendor/carrierwave
+ url = https://github.com/carrierwaveuploader/carrierwave
View
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
["uuid", "~> 2.3"],
# with carrierwave 0.11.1 and 0.11.2 wagn hangs in a loop on creating
# style and script machine output
- ["carrierwave", "<= 0.11.0"],
+ #["carrierwave", "<= 0.11.0"],
["htmlentities", "~> 4.3"],
["mini_magick", "~> 4.2"],
# recaptcha 0.4.0 is last version that doesn't require ruby 2.0
View
@@ -1,5 +1,10 @@
# -*- encoding : utf-8 -*-
+cw_path = File.expand_path "../../vendor/carrierwave/lib", __FILE__
+$LOAD_PATH.unshift(cw_path) unless $LOAD_PATH.include?(cw_path)
require "carrierwave"
+require "carrierwave/storage/fog"
+require "fog"
+
# if Cardio.file_buckets.present?
# require "carrierwave/storage/fog"
# Cardio.file_buckets.each do |bucket, config|
@@ -21,9 +21,9 @@ def ensure_set &block
def attachment name, args
include_set Abstract::Attachment
- add_attributes name, "remote_#{name}_url".to_sym, :load_from_mod,
- :action_id_of_cached_upload, :empty_ok,
- :bucket, :storage_type
+ add_attributes name, "remote_#{name}_url".to_sym,
+ :action_id_of_cached_upload, :empty_ok, :load_from_mod,
+ :storage_type, :bucket, :mod
uploader_class = args[:uploader] || ::CarrierWave::FileCardUploader
mount_uploader name, uploader_class
end
@@ -1,3 +1,5 @@
+cw_path = File.expand_path "../../../../../vendor/carrierwave/lib", __FILE__
+$LOAD_PATH.unshift(cw_path) unless $LOAD_PATH.include?(cw_path)
require "carrierwave"
module CarrierWave
@@ -85,10 +87,17 @@ def remote_#{column}_url=(url)
end
end
+ def remove_#{column}=(value)
+ column = _mounter(:#{column}).serialization_column
+ send(:"\#{column}_will_change!")
+ super
+ end
+
def remove_#{column}!
+ self.remove_#{column} = true
+ write_#{column}_identifier
+ self.remove_#{column} = false
super
- _mounter(:#{column}).remove = true
- _mounter(:#{column}).write_identifier
end
def #{column}_will_change!
@@ -156,7 +156,6 @@ def action_id
def storage
case @model.storage_type
when :cloud then ::CarrierWave::Storage::Fog.new(self)
- when :web then ::CarrierWave::Storage::Web.new(self)
else ::CarrierWave::Storage::File.new(self)
end
end
@@ -1,5 +1,7 @@
require "carrier_wave/cardmount"
+attr_writer :empty_ok
+
def self.included host_class
host_class.extend CarrierWave::CardMount
end
@@ -12,7 +14,7 @@ def self.included host_class
# an id
event :correct_identifier, :finalize,
on: :create, when: proc { |c| !c.web? } do
- update_column(:db_content, attachment.db_content(mod: load_from_mod))
+ update_column(:db_content, attachment.db_content(mod: mod))
expire
end
@@ -24,89 +26,26 @@ def self.included host_class
event :validate_file_exist, :validate,
on: :create, when: proc { |c| !c.web? } do
- unless attachment.file.present? || empty_ok?
- errors.add attachment_name, "is missing"
- end
+ return if attachment.file.present? || empty_ok?
+ errors.add attachment_name, "is missing"
end
event :write_identifier, after: :save_original_filename,
when: proc { |c| !c.web? } do
- self.content = attachment.db_content(mod: load_from_mod)
-end
-
-event :create_public_link, :integrate,
- on: :save, when: proc { |c| c.unprotected? } do
- return if File.exist? public_path
- FileUtils.mkdir_p File.dirname(public_path)
- File.symlink attachment.path, public_path
-end
-
-event :storage_type_change, :store,
- on: :update, when: proc { |c| c.storage_type_changed? } do
- return if storage_type.in? [:web, :coded]
- return if @new_storage_type.in? [:web, :coded]
-
- case storage_type
- when :cloud
- if @new_storage_type == :cloud
- move_from_cloud_to_cloud
- else
- move_from_cloud_to_local
- end
- when :protected, :unprotected
- if @new_storage_type == :cloud
- move_from_local_to_cloud
- end
- end
- #attachment.url
- #binding.pry
- # @bucket = @new_bucket
- # @storage_type = @new_storage_type
- #
- # write_identifier
-end
-
-event :remove_public_link, before: :storage_type_change,
- on: :update, when: proc { |c| !c.unprotected? } do
- return unless File.exist? public_path
- File.rm public_path
+ self.content = attachment.db_content(mod: mod)
end
def public_path
Cardio.paths["public"].existent.first + file.url
end
-def move_from_cloud_to_cloud
- #old_url = attachment.url
- #upload_cache_card.update_attributes! remote_file_url: url
-end
-
-def move_from_cloud_to_local
- raise Card::Error, "storage type change from :cloud to #{@new_storage_type} "\
- "is not supported"
-end
-
-def move_from_local_to_cloud
- old_file = attachment.file
- @bucket = @new_bucket
- @storage_type = @new_storage_type
- #self.attachment.store!
- write_identifier
- self.attachment.store! old_file
-end
-
def file_ready_to_save?
attachment.file.present? &&
!preliminary_upload? &&
!save_preliminary_upload? &&
attachment_changed?
end
-def storage_type_changed?
- @new_bucket || @new_storage_type
-end
-
-
def store_dir
@store_in_mod ? mod_dir : upload_dir
end
@@ -135,43 +74,10 @@ def create_versions?
true
end
-attr_writer :empty_ok
-attr_writer :bucket, :storage_type
-
def empty_ok?
@empty_ok
end
-def bucket= value
- if @action == :update
- @update_storage = true
- @new_bucket = value
- else
- @bucket = value
- end
-end
-
-def storage_type= value
- if @action == :update
- # we cant update the storage type directly here
- # if we do then the uploader doesn't find the file we want to update
- @update_storage = true
- @new_storage_type = value
- else
- @storage_type = value
- end
-end
-
-def load_from_mod= value
- @mod = value
- write_identifier
- @store_in_mod = true if value
-end
-
-def load_from_mod
- @mod
-end
-
# place for files of regular file cards
def upload_dir
id ? "#{files_base_dir}/#{id}" : tmp_upload_dir
@@ -190,53 +96,6 @@ def files_base_dir
bucket ? bucket_config[:subdirectory] : Card.paths["files"].existent.first
end
-def bucket
- @bucket ||= cloud? &&
- ((new_card? && bucket_from_config) || bucket_from_content)
-end
-
-def cloud?
- storage_type == :cloud
-end
-
-def web?
- storage_type == :web
-end
-
-def remote_storage?
- cloud? || storage_type == :web
-end
-
-def bucket_config
- return {} unless bucket
- @bucket_config ||= Cardio.config.file_buckets[bucket].deep_symbolize_keys || {}
-end
-
-def bucket_from_content
- return unless content
- content.match(/^\((?<bucket>[^)]+)\)/) { |m| m[:bucket] }
-end
-
-def bucket_from_config
- Cardio.config.file_default_bucket ||
- (Cardio.config.file_buckets && Cardio.config.file_buckets.keys.first)
-end
-
-def mod_file?
- return @mod if @store_in_mod
- # when db_content was changed assume that it's no longer a mod file
- return if db_content_changed? || !content.present?
- case content
- when %r{^:[^/]+/([^.]+)} then Regexp.last_match(1) # current mod_file format
- when /^\~/ then false # current id file format
- else
- if (lines = content.split("\n")) && (lines.size == 4)
- # old format, still used in card_changes.
- lines.last
- end
- end
-end
-
def assign_set_specific_attributes
# reset content if we really have something to upload
if @set_specific.present? && @set_specific[attachment_name.to_s].present?
@@ -249,9 +108,7 @@ def delete_files_for_action action
with_selected_action_id(action.id) do
attachment.file.delete
attachment.versions.each_value do |version|
- binding.pry
- version.delete
- #FileUtils.rm version.path
+ version.file.delete
end
end
end
@@ -277,35 +134,3 @@ def attachment_format ext
Rails.logger.info "attachment_format issue: #{e.message}"
nil
end
-
-def storage_type
- @storage_type ||=
- new_card? ? storage_type_from_config : storage_type_from_content
-end
-
-def storage_type_from_config
- return unless (type = Cardio.config.file_storage)
- unless type.in? CarrierWave::FileCardUploader::STORAGE_TYPES
- raise Card::Error,
- I18n.t(:error_invalid_storage_type,
- scope: "mod.carrierwave.set.abstract.attachment",
- type: type)
- end
- type
-end
-
-def storage_type_from_content
- case content
- when /^\(/ then :cloud
- when %r{/^https?\:/} then :web
- when /^~/ then :protected
- when /^\:/ then :coded
- else :unprotected
- end
-end
-
-def update_storage_location! storage_type=nil, bucket=nil
- storage_type ||= storage_type_from_config
- bucket ||= bucket_from_config if storage_type == :cloud
- update_attributes! storage_type: storage_type, bucket: bucket
-end
Oops, something went wrong.

0 comments on commit 7442cfa

Please sign in to comment.