class Refile::AttachmentDefinition
@api private
Attributes
cache[R]
name[R]
options[R]
record[R]
remove[RW]
store[R]
type[R]
valid_content_types[R]
valid_extensions[R]
Public Class Methods
new(name, cache:, store:, raise_errors: true, type: nil, extension: nil, content_type: nil)
click to toggle source
# 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
Public Instance Methods
accept()
click to toggle source
# 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?()
click to toggle source
# File lib/refile/attachment_definition.rb, line 34 def raise_errors? @raise_errors end
validate(attacher)
click to toggle source
# 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