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.
29 30 31 |
# File 'lib/paperclip/attachment_registry.rb', line 29 def initialize clear end |
Class Method Details
.clear ⇒ Object
13 14 15 |
# File 'lib/paperclip/attachment_registry.rb', line 13 def self.clear instance.clear end |
.definitions_for(klass) ⇒ Object
25 26 27 |
# File 'lib/paperclip/attachment_registry.rb', line 25 def self.definitions_for(klass) instance.definitions_for(klass) end |
.each_definition(&block) ⇒ Object
21 22 23 |
# File 'lib/paperclip/attachment_registry.rb', line 21 def self.each_definition(&block) instance.each_definition(&block) end |
.names_for(klass) ⇒ Object
17 18 19 |
# File 'lib/paperclip/attachment_registry.rb', line 17 def self.names_for(klass) instance.names_for(klass) end |
.register(klass, attachment_name, attachment_options) ⇒ Object
9 10 11 |
# File 'lib/paperclip/attachment_registry.rb', line 9 def self.register(klass, , ) instance.register(klass, , ) end |
Instance Method Details
#clear ⇒ Object
39 40 41 |
# File 'lib/paperclip/attachment_registry.rb', line 39 def clear @attachments = Hash.new { |h, k| h[k] = {} } end |
#definitions_for(klass) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/paperclip/attachment_registry.rb', line 55 def definitions_for(klass) parent_classes = klass.ancestors.reverse parent_classes.each_with_object({}) do |ancestor, inherited_definitions| inherited_definitions.deep_merge! @attachments[ancestor] end end |
#each_definition ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/paperclip/attachment_registry.rb', line 47 def each_definition @attachments.each do |klass, | .each do |name, | yield klass, name, end end end |
#names_for(klass) ⇒ Object
43 44 45 |
# File 'lib/paperclip/attachment_registry.rb', line 43 def names_for(klass) @attachments[klass].keys end |
#register(klass, attachment_name, attachment_options) ⇒ Object
33 34 35 36 37 |
# File 'lib/paperclip/attachment_registry.rb', line 33 def register(klass, , ) @attachments ||= {} @attachments[klass] ||= {} @attachments[klass][] = end |