Object
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
@overload self.attr_reader(attr)
@param attr [Symbol]
@overload self.attr_reader(attrs)
@param attrs [Array<Symbol>]
# File lib/twitter/base.rb, line 15 def self.attr_reader(*attrs) attrs.each do |attribute| class_eval do define_method attribute do @attrs[attribute.to_sym] end end end end
Retrieves an object from the identity map.
@param attrs [Hash] @return [Twitter::Base]
# File lib/twitter/base.rb, line 37 def self.fetch(attrs) return unless identity_map if object = identity_map.fetch(Marshal.dump(attrs)) return object end return yield if block_given? raise Twitter::Error::IdentityMapKeyError, "key not found" end
Retrieves an object from the identity map, or stores it in the identity map if it doesn't already exist.
@param attrs [Hash] @return [Twitter::Base]
# File lib/twitter/base.rb, line 68 def self.fetch_or_new(attrs={}) return unless attrs return new(attrs) unless identity_map fetch(attrs) do object = new(attrs) store(object) end end
Returns a new object based on the response hash
@param response [Hash] @return [Twitter::Base]
# File lib/twitter/base.rb, line 59 def self.from_response(response={}) fetch_or_new(response[:body]) end
return [Twitter::IdentityMap]
# File lib/twitter/base.rb, line 26 def self.identity_map return unless Twitter.identity_map @identity_map = Twitter.identity_map.new if @identity_map_class != Twitter.identity_map @identity_map_class = Twitter.identity_map @identity_map end
Fetches an attribute of an object using hash notation
@param method [String, Symbol] Message to send to the object
# File lib/twitter/base.rb, line 89 def [](method) send(method.to_sym) rescue NoMethodError nil end
Generated with the Darkfish Rdoc Generator 2.