Class: Cachai::Response

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/models.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/models.rb', line 140

def as_json(options = {})
  {
    :id           => id,
    :author_name  => author_name,
    # :author_email => author_email,
    :author_img   => author_img,
    :author_url   => author_url,
    :content      => content,
    :timestamp    => created_at.to_i,
    :parent_id    => parent_id,
    :type         => response_type,
    # :created_at   => created_at,
    :created_ago  => Timeago.since(created_at)
  }
end

#author_img(size = 50) ⇒ Object



156
157
158
159
# File 'lib/models.rb', line 156

def author_img(size = 50)
  id = Digest::MD5::hexdigest(author_email.strip.downcase)
  "https://www.gravatar.com/avatar/#{id}.jpg?s=#{size}"
end

#parentObject



136
137
138
# File 'lib/models.rb', line 136

def parent
  @parent ||= Response.find(parent_id) rescue nil
end