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
- #valid_extensions ⇒ 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
- #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 @valid_extensions = [extension].flatten if 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 |
#valid_extensions ⇒ 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_extensions @valid_extensions 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 |
#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.
38 39 40 41 42 43 44 45 |
# File 'lib/refile/attachment_definition.rb', line 38 def validate(attacher) errors = [] extension_included = valid_extensions && valid_extensions.map(&:downcase).include?(attacher.extension.to_s.downcase) errors << :invalid_extension if valid_extensions and not extension_included errors << :invalid_content_type if valid_content_types and not valid_content_types.include?(attacher.content_type) errors << :too_large if cache.max_size and attacher.size and attacher.size >= cache.max_size errors end |