| 1 |
|
| 2 |
|
| 3 |
module Plugin::Photo |
| 4 |
class InnerPhoto < Diva::Model |
| 5 |
include Diva::Model::PhotoMixin |
| 6 |
|
| 7 |
field.uri :perma_link, required: true |
| 8 |
|
| 9 |
def self.photos |
| 10 |
@photos ||= TimeLimitedStorage.new(Integer, self) |
| 11 |
end |
| 12 |
|
| 13 |
def self.[](uri) |
| 14 |
case uri |
| 15 |
when Photo |
| 16 |
uri.maximum_original |
| 17 |
when Diva::Model |
| 18 |
uri |
| 19 |
when URI, Addressable::URI, Diva::URI, String |
| 20 |
wrapped_uri = Diva::URI(uri) |
| 21 |
photos[wrapped_uri.to_s.hash] ||= new(perma_link: wrapped_uri) |
| 22 |
end |
| 23 |
end |
| 24 |
|
| 25 |
def initialize(*params) |
| 26 |
super |
| 27 |
self.class.photos[uri.to_s.hash] = self |
| 28 |
end |
| 29 |
end |
| 30 |
end |