mini-smart-pkg 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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/carrierwave-3.1.3/README.md +1214 -0
  3. data/carrierwave-3.1.3/lib/carrierwave/compatibility/paperclip.rb +105 -0
  4. data/carrierwave-3.1.3/lib/carrierwave/downloader/base.rb +101 -0
  5. data/carrierwave-3.1.3/lib/carrierwave/downloader/remote_file.rb +68 -0
  6. data/carrierwave-3.1.3/lib/carrierwave/error.rb +8 -0
  7. data/carrierwave-3.1.3/lib/carrierwave/locale/en.yml +17 -0
  8. data/carrierwave-3.1.3/lib/carrierwave/mount.rb +446 -0
  9. data/carrierwave-3.1.3/lib/carrierwave/mounter.rb +257 -0
  10. data/carrierwave-3.1.3/lib/carrierwave/orm/activerecord.rb +68 -0
  11. data/carrierwave-3.1.3/lib/carrierwave/processing/mini_magick.rb +362 -0
  12. data/carrierwave-3.1.3/lib/carrierwave/processing/rmagick.rb +433 -0
  13. data/carrierwave-3.1.3/lib/carrierwave/processing/vips.rb +315 -0
  14. data/carrierwave-3.1.3/lib/carrierwave/processing.rb +3 -0
  15. data/carrierwave-3.1.3/lib/carrierwave/sanitized_file.rb +361 -0
  16. data/carrierwave-3.1.3/lib/carrierwave/storage/abstract.rb +43 -0
  17. data/carrierwave-3.1.3/lib/carrierwave/storage/file.rb +124 -0
  18. data/carrierwave-3.1.3/lib/carrierwave/storage/fog.rb +560 -0
  19. data/carrierwave-3.1.3/lib/carrierwave/storage.rb +3 -0
  20. data/carrierwave-3.1.3/lib/carrierwave/test/matchers.rb +398 -0
  21. data/carrierwave-3.1.3/lib/carrierwave/uploader/cache.rb +223 -0
  22. data/carrierwave-3.1.3/lib/carrierwave/uploader/callbacks.rb +33 -0
  23. data/carrierwave-3.1.3/lib/carrierwave/uploader/configuration.rb +229 -0
  24. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_allowlist.rb +62 -0
  25. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_denylist.rb +65 -0
  26. data/carrierwave-3.1.3/lib/carrierwave/uploader/default_url.rb +17 -0
  27. data/carrierwave-3.1.3/lib/carrierwave/uploader/dimension.rb +66 -0
  28. data/carrierwave-3.1.3/lib/carrierwave/uploader/download.rb +24 -0
  29. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_allowlist.rb +63 -0
  30. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_denylist.rb +64 -0
  31. data/carrierwave-3.1.3/lib/carrierwave/uploader/file_size.rb +43 -0
  32. data/carrierwave-3.1.3/lib/carrierwave/uploader/mountable.rb +44 -0
  33. data/carrierwave-3.1.3/lib/carrierwave/uploader/processing.rb +128 -0
  34. data/carrierwave-3.1.3/lib/carrierwave/uploader/proxy.rb +99 -0
  35. data/carrierwave-3.1.3/lib/carrierwave/uploader/remove.rb +21 -0
  36. data/carrierwave-3.1.3/lib/carrierwave/uploader/serialization.rb +28 -0
  37. data/carrierwave-3.1.3/lib/carrierwave/uploader/store.rb +168 -0
  38. data/carrierwave-3.1.3/lib/carrierwave/uploader/url.rb +44 -0
  39. data/carrierwave-3.1.3/lib/carrierwave/uploader/versions.rb +352 -0
  40. data/carrierwave-3.1.3/lib/carrierwave/uploader.rb +69 -0
  41. data/carrierwave-3.1.3/lib/carrierwave/utilities/file_name.rb +47 -0
  42. data/carrierwave-3.1.3/lib/carrierwave/utilities/uri.rb +26 -0
  43. data/carrierwave-3.1.3/lib/carrierwave/utilities.rb +7 -0
  44. data/carrierwave-3.1.3/lib/carrierwave/validations/active_model.rb +76 -0
  45. data/carrierwave-3.1.3/lib/carrierwave/version.rb +3 -0
  46. data/carrierwave-3.1.3/lib/carrierwave.rb +108 -0
  47. data/carrierwave-3.1.3/lib/generators/templates/uploader.rb.erb +56 -0
  48. data/carrierwave-3.1.3/lib/generators/uploader_generator.rb +7 -0
  49. data/mini-smart-pkg.gemspec +12 -0
  50. metadata +89 -0
@@ -0,0 +1,128 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Processing
4
+ extend ActiveSupport::Concern
5
+
6
+ include CarrierWave::Uploader::Callbacks
7
+
8
+ included do
9
+ class_attribute :processors, :instance_writer => false
10
+ self.processors = []
11
+
12
+ before :cache, :process!
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ ##
18
+ # Adds a processor callback which applies operations as a file is uploaded.
19
+ # The argument may be the name of any method of the uploader, expressed as a symbol,
20
+ # or a list of such methods, or a hash where the key is a method and the value is
21
+ # an array of arguments to call the method with. Also accepts an :if or :unless condition
22
+ #
23
+ # === Parameters
24
+ #
25
+ # args (*Symbol, Hash{Symbol => Array[]})
26
+ #
27
+ # === Examples
28
+ #
29
+ # class MyUploader < CarrierWave::Uploader::Base
30
+ #
31
+ # process :sepiatone, :vignette
32
+ # process :scale => [200, 200]
33
+ # process :scale => [200, 200], :if => :image?
34
+ # process :scale => [200, 200], :unless => :disallowed_image_type?
35
+ # process :sepiatone, :if => :image?
36
+ #
37
+ # def sepiatone
38
+ # ...
39
+ # end
40
+ #
41
+ # def vignette
42
+ # ...
43
+ # end
44
+ #
45
+ # def scale(height, width)
46
+ # ...
47
+ # end
48
+ #
49
+ # def image?
50
+ # ...
51
+ # end
52
+ #
53
+ # def disallowed_image_type?
54
+ # ...
55
+ # end
56
+ #
57
+ # end
58
+ #
59
+ def process(*args)
60
+ new_processors = args.inject({}) do |hash, arg|
61
+ arg = { arg => [] } unless arg.is_a?(Hash)
62
+ hash.merge!(arg)
63
+ end
64
+
65
+ condition_type = new_processors.keys.detect { |key| [:if, :unless].include?(key) }
66
+ condition = new_processors.delete(:if) || new_processors.delete(:unless)
67
+ new_processors.each do |processor, processor_args|
68
+ self.processors += [[processor, processor_args, condition, condition_type]]
69
+
70
+ if processor == :convert
71
+ # Treat :convert specially, since it should trigger the file extension change
72
+ force_extension processor_args
73
+ if condition
74
+ warn "Use of 'process convert: format' with conditionals has an issue and doesn't work correctly. See https://github.com/carrierwaveuploader/carrierwave/issues/2723 for details. "
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end # ClassMethods
80
+
81
+ ##
82
+ # Apply all process callbacks added through CarrierWave.process
83
+ #
84
+ def process!(new_file=nil)
85
+ return unless enable_processing
86
+
87
+ with_callbacks(:process, new_file) do
88
+ self.class.processors.each do |method, args, condition, condition_type|
89
+ if condition && condition_type == :if
90
+ if condition.respond_to?(:call)
91
+ next unless condition.call(self, :args => args, :method => method, :file => new_file)
92
+ else
93
+ next unless self.send(condition, new_file)
94
+ end
95
+ elsif condition && condition_type == :unless
96
+ if condition.respond_to?(:call)
97
+ next if condition.call(self, :args => args, :method => method, :file => new_file)
98
+ elsif self.send(condition, new_file)
99
+ next
100
+ end
101
+ end
102
+
103
+ if args.is_a? Array
104
+ kwargs, args = args.partition { |arg| arg.is_a? Hash }
105
+ end
106
+
107
+ if kwargs.present?
108
+ kwargs = kwargs.reduce(:merge)
109
+ self.send(method, *args, **kwargs)
110
+ else
111
+ self.send(method, *args)
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ def forcing_extension(filename)
120
+ if force_extension && filename
121
+ Pathname.new(filename).sub_ext(".#{force_extension.to_s.delete_prefix('.')}").to_s
122
+ else
123
+ filename
124
+ end
125
+ end
126
+ end # Processing
127
+ end # Uploader
128
+ end # CarrierWave
@@ -0,0 +1,99 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Proxy
4
+
5
+ ##
6
+ # === Returns
7
+ #
8
+ # [Boolean] Whether the uploaded file is blank
9
+ #
10
+ def blank?
11
+ file.blank?
12
+ end
13
+
14
+ ##
15
+ # === Returns
16
+ #
17
+ # [String] the path where the file is currently located.
18
+ #
19
+ def current_path
20
+ file.try(:path)
21
+ end
22
+
23
+ alias_method :path, :current_path
24
+
25
+ ##
26
+ # Returns a string that uniquely identifies the retrieved or last stored file
27
+ #
28
+ # === Returns
29
+ #
30
+ # [String] uniquely identifies a file
31
+ #
32
+ def identifier
33
+ @identifier || (file && storage.try(:identifier))
34
+ end
35
+
36
+ ##
37
+ # Returns a String which is to be used as a temporary value which gets assigned to the column.
38
+ # The purpose is to mark the column that it will be updated. Finally before the save it will be
39
+ # overwritten by the #identifier value, which is usually #filename.
40
+ #
41
+ # === Returns
42
+ #
43
+ # [String] a temporary_identifier, by default the value of #cache_name is used
44
+ #
45
+ def temporary_identifier
46
+ cache_name || @identifier
47
+ end
48
+
49
+ ##
50
+ # Read the contents of the file
51
+ #
52
+ # === Returns
53
+ #
54
+ # [String] contents of the file
55
+ #
56
+ def read(*args)
57
+ file.try(:read, *args)
58
+ end
59
+
60
+ ##
61
+ # Fetches the size of the currently stored/cached file
62
+ #
63
+ # === Returns
64
+ #
65
+ # [Integer] size of the file
66
+ #
67
+ def size
68
+ file.try(:size) || 0
69
+ end
70
+
71
+ ##
72
+ # Return the size of the file when asked for its length
73
+ #
74
+ # === Returns
75
+ #
76
+ # [Integer] size of the file
77
+ #
78
+ # === Note
79
+ #
80
+ # This was added because of the way Rails handles length/size validations in 3.0.6 and above.
81
+ #
82
+ def length
83
+ size
84
+ end
85
+
86
+ ##
87
+ # Read the content type of the file
88
+ #
89
+ # === Returns
90
+ #
91
+ # [String] content type of the file
92
+ #
93
+ def content_type
94
+ file.try(:content_type)
95
+ end
96
+
97
+ end # Proxy
98
+ end # Uploader
99
+ end # CarrierWave
@@ -0,0 +1,21 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Remove
4
+ extend ActiveSupport::Concern
5
+
6
+ include CarrierWave::Uploader::Callbacks
7
+
8
+ ##
9
+ # Removes the file and reset it
10
+ #
11
+ def remove!
12
+ with_callbacks(:remove) do
13
+ @file.delete if @file
14
+ @file = nil
15
+ @cache_id = nil
16
+ end
17
+ end
18
+
19
+ end # Remove
20
+ end # Uploader
21
+ end # CarrierWave
@@ -0,0 +1,28 @@
1
+ require "json"
2
+ require "active_support/core_ext/hash"
3
+
4
+ module CarrierWave
5
+ module Uploader
6
+ module Serialization
7
+ extend ActiveSupport::Concern
8
+
9
+ def serializable_hash(options = nil)
10
+ {"url" => url}.merge Hash[versions.map { |name, version| [name.to_s, { "url" => version.url }] }]
11
+ end
12
+
13
+ def as_json(options=nil)
14
+ serializable_hash
15
+ end
16
+
17
+ def to_json(options=nil)
18
+ JSON.generate(as_json)
19
+ end
20
+
21
+ def to_xml(options={})
22
+ merged_options = options.merge(:root => mounted_as || "uploader", :type => 'uploader')
23
+ serializable_hash.to_xml(merged_options)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,168 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Store
4
+ extend ActiveSupport::Concern
5
+
6
+ include CarrierWave::Uploader::Callbacks
7
+ include CarrierWave::Uploader::Configuration
8
+ include CarrierWave::Uploader::Cache
9
+
10
+ included do
11
+ prepend Module.new {
12
+ def initialize(*)
13
+ super
14
+ @file, @filename, @cache_id, @identifier, @deduplication_index = nil
15
+ end
16
+ }
17
+
18
+ after :store, :show_warning_when_filename_is_unavailable
19
+
20
+ class_attribute :filename_safeguard_checked
21
+ end
22
+
23
+ module ClassMethods
24
+ private
25
+
26
+ def inherited(subclass)
27
+ # To perform the filename safeguard check once per a class
28
+ self.filename_safeguard_checked = false
29
+ super
30
+ end
31
+ end
32
+
33
+ ##
34
+ # Override this in your Uploader to change the filename.
35
+ #
36
+ # Be careful using record ids as filenames. If the filename is stored in the database
37
+ # the record id will be nil when the filename is set. Don't use record ids unless you
38
+ # understand this limitation.
39
+ #
40
+ # Do not use the version_name in the filename, as it will prevent versions from being
41
+ # loaded correctly.
42
+ #
43
+ # === Returns
44
+ #
45
+ # [String] a filename
46
+ #
47
+ def filename
48
+ @filename
49
+ end
50
+
51
+ ##
52
+ # Returns a filename which doesn't conflict with already-stored files.
53
+ #
54
+ # === Returns
55
+ #
56
+ # [String] the filename with suffix added for deduplication
57
+ #
58
+ def deduplicated_filename
59
+ return unless filename
60
+ return filename unless @deduplication_index
61
+
62
+ parts = filename.split('.')
63
+ basename = parts.shift
64
+ basename.sub!(/ ?\(\d+\)\z/, '')
65
+ ([basename.to_s + (@deduplication_index > 1 ? "(#{@deduplication_index})" : '')] + parts).join('.')
66
+ end
67
+
68
+ ##
69
+ # Calculates the path where the file should be stored. If +for_file+ is given, it will be
70
+ # used as the identifier, otherwise +CarrierWave::Uploader#identifier+ is assumed.
71
+ #
72
+ # === Parameters
73
+ #
74
+ # [for_file (String)] name of the file <optional>
75
+ #
76
+ # === Returns
77
+ #
78
+ # [String] the store path
79
+ #
80
+ def store_path(for_file=identifier)
81
+ File.join([store_dir, full_filename(for_file)].compact)
82
+ end
83
+
84
+ ##
85
+ # Stores the file by passing it to this Uploader's storage engine.
86
+ #
87
+ # If new_file is omitted, a previously cached file will be stored.
88
+ #
89
+ # === Parameters
90
+ #
91
+ # [new_file (File, IOString, Tempfile)] any kind of file object
92
+ #
93
+ def store!(new_file=nil)
94
+ cache!(new_file) if new_file && !cached?
95
+ if !cache_only && @file && @cache_id
96
+ with_callbacks(:store, new_file) do
97
+ new_file = storage.store!(@file)
98
+ if delete_tmp_file_after_storage
99
+ @file.delete unless move_to_store
100
+ cache_storage.delete_dir!(cache_path(nil))
101
+ end
102
+ @file = new_file
103
+ @identifier = storage.identifier
104
+ @original_filename = @cache_id = @deduplication_index = nil
105
+ @staged = false
106
+ end
107
+ end
108
+ end
109
+
110
+ ##
111
+ # Retrieves the file from the storage.
112
+ #
113
+ # === Parameters
114
+ #
115
+ # [identifier (String)] uniquely identifies the file to retrieve
116
+ #
117
+ def retrieve_from_store!(identifier)
118
+ with_callbacks(:retrieve_from_store, identifier) do
119
+ @file = storage.retrieve!(identifier)
120
+ @identifier = identifier
121
+ end
122
+ end
123
+
124
+ ##
125
+ # Look for an identifier which doesn't collide with the given already-stored identifiers.
126
+ # It is done by adding a index number as the suffix.
127
+ # For example, if there's 'image.jpg' and the @deduplication_index is set to 2,
128
+ # The stored file will be named as 'image(2).jpg'.
129
+ #
130
+ # === Parameters
131
+ #
132
+ # [current_identifiers (Array[String])] List of identifiers for already-stored files
133
+ #
134
+ def deduplicate(current_identifiers)
135
+ @deduplication_index = nil
136
+ return unless current_identifiers.include?(identifier)
137
+
138
+ (1..current_identifiers.size + 1).each do |i|
139
+ @deduplication_index = i
140
+ break unless current_identifiers.include?(identifier)
141
+ end
142
+ end
143
+
144
+ private
145
+
146
+ def full_filename(for_file)
147
+ forcing_extension(for_file)
148
+ end
149
+
150
+ def show_warning_when_filename_is_unavailable(_)
151
+ return if self.class.filename_safeguard_checked
152
+ self.class.filename_safeguard_checked = true
153
+ return if filename
154
+
155
+ warn <<~MESSAGE
156
+ [WARNING] Your uploader's #filename method defined at #{method(:filename).source_location.join(':')} didn't return value after storing the file.
157
+ It's likely that the method is safeguarded with `if original_filename`, which were necessary for pre-3.x CarrierWave but is no longer needed.
158
+ Removing it is recommended, as it is known to cause issues depending on the use case: https://github.com/carrierwaveuploader/carrierwave/issues/2708
159
+ MESSAGE
160
+ end
161
+
162
+ def storage
163
+ @storage ||= self.class.storage.new(self)
164
+ end
165
+
166
+ end # Store
167
+ end # Uploader
168
+ end # CarrierWave
@@ -0,0 +1,44 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Url
4
+ extend ActiveSupport::Concern
5
+ include CarrierWave::Uploader::Configuration
6
+ include CarrierWave::Utilities::Uri
7
+
8
+ ##
9
+ # === Parameters
10
+ #
11
+ # [Hash] optional, the query params (only AWS)
12
+ #
13
+ # === Returns
14
+ #
15
+ # [String] the location where this file is accessible via a url
16
+ #
17
+ def url(options = {})
18
+ if file.respond_to?(:url)
19
+ tmp_url = file.method(:url).arity.zero? ? file.url : file.url(options)
20
+ return tmp_url if tmp_url.present?
21
+ end
22
+
23
+ if file.respond_to?(:path)
24
+ path = encode_path(file.path.sub(File.expand_path(root), ''))
25
+
26
+ if (host = asset_host)
27
+ if host.respond_to? :call
28
+ "#{host.call(file)}#{path}"
29
+ else
30
+ "#{host}#{path}"
31
+ end
32
+ else
33
+ (base_path || "") + path
34
+ end
35
+ end
36
+ end
37
+
38
+ def to_s
39
+ url || ''
40
+ end
41
+
42
+ end # Url
43
+ end # Uploader
44
+ end # CarrierWave