forked from thoughtbot/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Paperclip::Tasks::Attachment to Paperclip::AttachmentRegistry
- Loading branch information
Jon Yurek
committed
Jul 23, 2013
1 parent
65cc5c7
commit b62cc2d
Showing
13 changed files
with
101 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'singleton' | ||
|
||
module Paperclip | ||
class AttachmentRegistry | ||
include Singleton | ||
|
||
def self.register(klass, attachment_name, attachment_options) | ||
instance.register(klass, attachment_name, attachment_options) | ||
end | ||
|
||
def self.clear | ||
instance.clear | ||
end | ||
|
||
def self.names_for(klass) | ||
instance.names_for(klass) | ||
end | ||
|
||
def self.each_definition(&block) | ||
instance.each_definition(&block) | ||
end | ||
|
||
def self.definitions_for(klass) | ||
instance.definitions_for(klass) | ||
end | ||
|
||
def initialize | ||
clear | ||
end | ||
|
||
def register(klass, attachment_name, attachment_options) | ||
@attachments ||= {} | ||
@attachments[klass] ||= {} | ||
@attachments[klass][attachment_name] = attachment_options | ||
end | ||
|
||
def clear | ||
@attachments = Hash.new { |h,k| h[k] = {} } | ||
end | ||
|
||
def names_for(klass) | ||
@attachments[klass].keys | ||
end | ||
|
||
def each_definition | ||
@attachments.each do |klass, attachments| | ||
attachments.each do |name, options| | ||
yield klass, name, options | ||
end | ||
end | ||
end | ||
|
||
def definitions_for(klass) | ||
@attachments[klass] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters