Module: Twitter::ModelMixin::InstanceMethods

Defined in:
lib/vendor/twitter/lib/twitter/model.rb

Overview

Instance methods defined for Twitter::ModelMixin module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

:nodoc:



49
50
51
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 49

def client
  @client
end

Instance Method Details

#bless(client) ⇒ Object

“Blesses” model object.

Should be overridden by model class if special behavior is expected

Expected to return blessed object (usually self)



113
114
115
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 113

def bless(client)
  self.basic_bless(client)
end

#eql?(other) ⇒ Boolean

Equality method override of Object#eql? default.

Relies on the class using this mixin to provide a attributes class method that will return an Array of attributes to check are equivalent in this #eql? override.

It is by design that the #eql? method will raise a NoMethodError if no attributes class method exists, to alert you that you must provide it for a meaningful result from this #eql? override. Otherwise this will return a meaningless result.

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 60

def eql?(other)
  attrs = self.class.attributes
  attrs.each do |att|
    return false unless self.send(att).eql?(other.send(att))
  end
  true
end

#to_hashObject

Returns hash representation of model object instance.

For example,

u = Twitter::User.new(:id => 2342342, :screen_name => 'tony_blair_is_the_devil')
u.to_hash #=> {:id => 2342342, :screen_name => 'tony_blair_is_the_devil'}

This method also requires that the class method attributes be defined to return an Array of attributes for the class.



97
98
99
100
101
102
103
104
105
106
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 97

def to_hash
  attrs = self.class.attributes
  result = {}
  attrs.each do |att|
    value = self.send(att)
    value = value.to_hash if value.respond_to?(:to_hash)
    result[att] = value if value
  end
  result
end

#to_iObject

Returns integer representation of model object instance.

For example,

status = Twitter::Status.new(:id => 234343)
status.to_i #=> 234343


73
74
75
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 73

def to_i
  @id
end

#to_sObject

Returns string representation of model object instance.

For example,

status = Twitter::Status.new(:text => 'my status message')
status.to_s #=> 'my status message'

If a model class doesn’t have a @text attribute defined the default Object#to_s will be returned as the result.



85
86
87
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 85

def to_s
  self.respond_to?(:text) ? @text : super.to_s
end