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

- (AttachmentRegistry) initialize

Returns a new instance of AttachmentRegistry



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

def initialize
  clear
end

Class Method Details

+ (Object) clear



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

def self.clear
  instance.clear
end

+ (Object) definitions_for(klass)



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

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

+ (Object) each_definition(&block)



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

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

+ (Object) names_for(klass)



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

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

+ (Object) register(klass, attachment_name, attachment_options)



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

- (Object) clear



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

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

- (Object) definitions_for(klass)



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

- (Object) each_definition



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

- (Object) names_for(klass)



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

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

- (Object) register(klass, attachment_name, attachment_options)



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