Class: FlickrMocks::Models::PhotoDetails
- Inherits:
-
Object
- Object
- FlickrMocks::Models::PhotoDetails
- Defined in:
- lib/flickr_mocks/models/photo_details.rb
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
readonly
returns the array of PhotoSize objects available for the given photo.
Instance Method Summary collapse
-
#==(other) ⇒ Object
compares the complete internal state of two PhotoDetails objects rather than simply comparing object_id’s.
-
#author ⇒ Object
returns the name of the author for the photo.
-
#delegated_instance_methods ⇒ Object
returns list of methods that are delegated to other objects.
-
#initialize(photo, dimensions) ⇒ PhotoDetails
constructor
A new instance of PhotoDetails.
-
#initialize_copy(orig) ⇒ Object
compares value for internal state rather than object_id.
-
#method_missing(id, *args, &block) ⇒ Object
delegates methods that are returned by delegated instance method.
-
#methods ⇒ Object
returns delegated methods as well as regular methods.
- #old_methods ⇒ Object
- #old_respond_to? ⇒ Object
-
#owner_name ⇒ Object
returns the owner name for the photo.
-
#owner_username ⇒ Object
returns the owner username for the photo.
-
#photo ⇒ Object
returns the raw FlicrkRaw response for the photo from flickr.
-
#possible_sizes ⇒ Object
returns the list of acceptable sizes for a photo.
-
#respond_to?(method, type = false) ⇒ Boolean
returns true for delegated and regular methods.
Constructor Details
#initialize(photo, dimensions) ⇒ PhotoDetails
Returns a new instance of PhotoDetails.
6 7 8 9 10 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 6 def initialize(photo,dimensions) self.dimensions = dimensions self.delegated_to_object= photo raise ArgumentError 'owner id for photo did not match owner id for at least one size' unless valid_owner_for_dimensions? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
delegates methods that are returned by delegated instance method. It also delegates array methods to the @dimensions object
55 56 57 58 59 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 55 def method_missing(id,*args,&block) return dimensions.sizes.send(id,*args,&block) if array_accessor_methods.include?(id) return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id) super end |
Instance Attribute Details
#dimensions ⇒ Object
returns the array of PhotoSize objects available for the given photo
29 30 31 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 29 def dimensions @dimensions end |
Instance Method Details
#==(other) ⇒ Object
compares the complete internal state of two PhotoDetails objects rather than simply comparing object_id’s
46 47 48 49 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 46 def ==(other) return false unless other.class == PhotoDetails (dimensions == other.dimensions) && (@delegated_to_object == other.instance_eval('@delegated_to_object')) end |
#author ⇒ Object
returns the name of the author for the photo. When owner_name is not available
owner_username is returned.
14 15 16 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 14 def owner_name.empty? ? owner_username : owner_name end |
#delegated_instance_methods ⇒ Object
returns list of methods that are delegated to other objects
74 75 76 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 74 def delegated_instance_methods @delegated_to_object.delegated_instance_methods + array_accessor_methods + [:owner_id] + possible_sizes end |
#initialize_copy(orig) ⇒ Object
compares value for internal state rather than object_id
79 80 81 82 83 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 79 def initialize_copy(orig) super @dimensions = @dimensions.clone @delegated_to_object = @delegated_to_object.clone end |
#methods ⇒ Object
returns delegated methods as well as regular methods
69 70 71 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 69 def methods delegated_instance_methods + old_methods end |
#old_methods ⇒ Object
67 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 67 alias :old_methods :methods |
#old_respond_to? ⇒ Object
61 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 61 alias :old_respond_to? :respond_to? |
#owner_name ⇒ Object
returns the owner name for the photo.
19 20 21 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 19 def owner_name self.owner.realname end |
#owner_username ⇒ Object
returns the owner username for the photo
24 25 26 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 24 def owner_username self.owner.username end |
#photo ⇒ Object
returns the raw FlicrkRaw response for the photo from flickr
40 41 42 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 40 def photo @delegated_to_object end |
#possible_sizes ⇒ Object
returns the list of acceptable sizes for a photo. Not every photo will have all of these sizes.
35 36 37 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 35 def possible_sizes FlickrMocks::Models::Helpers.possible_sizes end |
#respond_to?(method, type = false) ⇒ Boolean
returns true for delegated and regular methods
63 64 65 |
# File 'lib/flickr_mocks/models/photo_details.rb', line 63 def respond_to?(method,type=false) delegated_instance_methods.include?(method) || old_respond_to?(method) end |