Class: Paperclip::AttachmentRegistry
- Inherits:
-
Object
- Object
- Paperclip::AttachmentRegistry
- Includes:
- Singleton
- Defined in:
- lib/paperclip/attachment_registry.rb
Class Method Summary collapse
- .clear ⇒ Object
- .definitions_for(klass) ⇒ Object
- .each_definition(&block) ⇒ Object
- .names_for(klass) ⇒ Object
- .register(klass, attachment_name, attachment_options) ⇒ Object
Instance Method Summary collapse
- #clear ⇒ Object
- #definitions_for(klass) ⇒ Object
- #each_definition ⇒ Object
-
#initialize ⇒ AttachmentRegistry
constructor
A new instance of AttachmentRegistry.
- #names_for(klass) ⇒ Object
- #register(klass, attachment_name, attachment_options) ⇒ Object
Constructor Details
#initialize ⇒ AttachmentRegistry
Returns a new instance of AttachmentRegistry.
27 28 29 |
# File 'lib/paperclip/attachment_registry.rb', line 27 def initialize clear end |
Class Method Details
.clear ⇒ Object
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, , ) instance.register(klass, , ) end |
Instance Method Details
#clear ⇒ Object
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_definition ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/paperclip/attachment_registry.rb', line 45 def each_definition @attachments.each do |klass, | .each do |name, | yield klass, name, 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, , ) @attachments ||= {} @attachments[klass] ||= {} @attachments[klass][] = end |