Class: Refile::AttachmentDefinition Private
- Inherits:
-
Object
- Object
- Refile::AttachmentDefinition
- Defined in:
- lib/refile/attachment_definition.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #cache ⇒ Object readonly private
- #name ⇒ Object readonly private
- #options ⇒ Object readonly private
- #record ⇒ Object readonly private
- #remove ⇒ Object private
- #store ⇒ Object readonly private
- #type ⇒ Object readonly private
- #valid_content_types ⇒ Object readonly private
Instance Method Summary collapse
- #accept ⇒ Object private
-
#initialize(name, cache:, store:, raise_errors: true, type: nil, extension: nil, content_type: nil) ⇒ AttachmentDefinition
constructor
private
A new instance of AttachmentDefinition.
- #raise_errors? ⇒ Boolean private
- #valid_extensions ⇒ Object private
- #validate(attacher) ⇒ Object private
Constructor Details
#initialize(name, cache:, store:, raise_errors: true, type: nil, extension: nil, content_type: nil) ⇒ AttachmentDefinition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AttachmentDefinition.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/refile/attachment_definition.rb', line 7 def initialize(name, cache:, store:, raise_errors: true, type: nil, extension: nil, content_type: nil) @name = name @raise_errors = raise_errors @cache_name = cache @store_name = store @type = type @extension = extension @valid_content_types = [content_type].flatten if content_type @valid_content_types ||= Refile.types.fetch(type).content_type if type end |
Instance Attribute Details
#cache ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def cache @cache end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def @options end |
#record ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def record @record end |
#remove ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/refile/attachment_definition.rb', line 5 def remove @remove end |
#store ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def store @store end |
#type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def type @type end |
#valid_content_types ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 |
# File 'lib/refile/attachment_definition.rb', line 4 def valid_content_types @valid_content_types end |
Instance Method Details
#accept ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 31 32 |
# File 'lib/refile/attachment_definition.rb', line 26 def accept if valid_content_types valid_content_types.join(",") elsif valid_extensions valid_extensions.map { |e| ".#{e}" }.join(",") end end |
#raise_errors? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/refile/attachment_definition.rb', line 34 def raise_errors? @raise_errors end |
#valid_extensions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 45 |
# File 'lib/refile/attachment_definition.rb', line 38 def valid_extensions return unless @extension if @extension.is_a?(Proc) Array(@extension.call) else Array(@extension) end end |
#validate(attacher) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/refile/attachment_definition.rb', line 47 def validate(attacher) extension = attacher.extension.to_s.downcase content_type = attacher.content_type.to_s.downcase content_type = content_type.split(";").first unless content_type.empty? errors = [] errors << extension_error_params(extension) if invalid_extension?(extension) errors << content_type_error_params(content_type) if invalid_content_type?(content_type) errors << :too_large if cache.max_size and attacher.size and attacher.size >= cache.max_size errors << :zero_byte_detected if attacher.size.to_i.zero? errors end |