Class: Post

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

Instance Method Summary collapse

Methods included from Flareshow::Searchable

search

Methods inherited from Flareshow::Resource

#cache, cache_response, #changes, create, #destroy, #destroyed?, find, #get, get_from_cache, #id, #initialize, list_cache, #method_missing, #method_name, #refresh, #resource_key, 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

Instance Method Details

#build_comment(attributes = {}) ⇒ Object

build a new comment but don’t immediately persist it



15
16
17
18
19
# File 'lib/post.rb', line 15

def build_comment(attributes={})
  c = Comment.new(attributes)
  c.post_id = self.id
  c
end

#build_file(file_path) ⇒ Object



27
28
29
30
# File 'lib/post.rb', line 27

def build_file(file_path)
  self.files ||= []
  self.files += [{"part_id" => "file_#{UUID.generate}", "file_path" => file_path}]
end

#create_comment(attributes = {}) ⇒ Object

create a new comment on the post



22
23
24
25
# File 'lib/post.rb', line 22

def create_comment(attributes={})
  c = build_comment(attributes)
  c.save
end

#create_file(file_path) ⇒ Object

upload a file to a post



33
34
35
36
37
38
# File 'lib/post.rb', line 33

def create_file(file_path)
  self.files = []
  self.build_file(file_path)
  self.save
  self.files = nil
end

permalink to this post



6
7
8
9
10
11
12
# File 'lib/post.rb', line 6

def permalink(mobile=false)
  if mobile
    "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}/shareflow/mobile/post/#{id}"
  else
    "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}/shareflow/p/#{id}"
  end
end