Class: FileAttachment

Inherits:
Flareshow::Resource show all
Extended by:
Flareshow::Searchable
Defined in:
lib/file_attachment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Flareshow::Searchable

search

Methods inherited from Flareshow::Resource

#cache, cache_response, #changes, create, default_params, #destroy, #destroyed?, find, first, #get, get_from_cache, #id, #initialize, list_cache, #method_missing, #method_name, #refresh, #resource_key, #save, #set, store, #update

Constructor Details

This class inherits a constructor from Flareshow::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Flareshow::Resource

Class Method Details

.resource_keyObject

file attachments has a resource key of files for querying the server



13
14
15
# File 'lib/file_attachment.rb', line 13

def resource_key
  "files"
end

Instance Method Details

#downloadObject

download the file contents



19
20
21
22
23
24
25
26
# File 'lib/file_attachment.rb', line 19

def download
  url = self.url
  unless url.match(/http/)
    url = "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}#{url}"
  end
  Flareshow::Util.log_info("getting #{url}")
  Flareshow::Service.http_get(url)
end

#postObject

post for this file



29
30
31
32
33
34
35
# File 'lib/file_attachment.rb', line 29

def post
  return false unless post_id
  post = Post.get_from_cache(post_id)
  post ||= Comment.get_from_cache(post_id)
  post ||= Post.find({:id => post_id})
  post ||= Comment.find({:id => post_id})
end

#userObject

user for this post



38
39
40
41
42
# File 'lib/file_attachment.rb', line 38

def user
  return User.current unless user_id
  user = User.get_from_cache(user_id)
  user || User.first({:id => user_id})
end