Class: Paperclip::AttachmentRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/paperclip/attachment_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttachmentRegistry

Returns a new instance of AttachmentRegistry



27
28
29
# File 'lib/paperclip/attachment_registry.rb', line 27

def initialize
  clear
end

Class Method Details

.clearObject



11
12
13
# File 'lib/paperclip/attachment_registry.rb', line 11

def self.clear
  instance.clear
end

.definitions_for(klass) ⇒ Object



23
24
25
# File 'lib/paperclip/attachment_registry.rb', line 23

def self.definitions_for(klass)
  instance.definitions_for(klass)
end

.each_definition(&block) ⇒ Object



19
20
21
# File 'lib/paperclip/attachment_registry.rb', line 19

def self.each_definition(&block)
  instance.each_definition(&block)
end

.names_for(klass) ⇒ Object



15
16
17
# File 'lib/paperclip/attachment_registry.rb', line 15

def self.names_for(klass)
  instance.names_for(klass)
end

.register(klass, attachment_name, attachment_options) ⇒ Object



7
8
9
# File 'lib/paperclip/attachment_registry.rb', line 7

def self.register(klass, attachment_name, attachment_options)
  instance.register(klass, attachment_name, attachment_options)
end

Instance Method Details

#clearObject



37
38
39
# File 'lib/paperclip/attachment_registry.rb', line 37

def clear
  @attachments = Hash.new { |h,k| h[k] = {} }
end

#definitions_for(klass) ⇒ Object



53
54
55
56
57
# File 'lib/paperclip/attachment_registry.rb', line 53

def definitions_for(klass)
  klass.ancestors.each_with_object({}) do |ancestor, inherited_definitions|
    inherited_definitions.merge! @attachments[ancestor]
  end
end

#each_definitionObject



45
46
47
48
49
50
51
# File 'lib/paperclip/attachment_registry.rb', line 45

def each_definition
  @attachments.each do |klass, attachments|
    attachments.each do |name, options|
      yield klass, name, options
    end
  end
end

#names_for(klass) ⇒ Object



41
42
43
# File 'lib/paperclip/attachment_registry.rb', line 41

def names_for(klass)
  @attachments[klass].keys
end

#register(klass, attachment_name, attachment_options) ⇒ Object



31
32
33
34
35
# File 'lib/paperclip/attachment_registry.rb', line 31

def register(klass, attachment_name, attachment_options)
  @attachments ||= {}
  @attachments[klass] ||= {}
  @attachments[klass][attachment_name] = attachment_options
end