Class: Refile::AttachmentDefinition Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#cacheObject (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

#nameObject (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

#optionsObject (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
  @options
end

#recordObject (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

#removeObject

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

#storeObject (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

#typeObject (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_typesObject (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_extensionsObject (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

#acceptObject

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.

Returns:

  • (Boolean)

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