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, default_params, #destroy, #destroyed?, find, first, #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



17
18
19
20
21
# File 'lib/post.rb', line 17

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

#build_file(file_path) ⇒ Object

build a new file object on the client but don’t commit to the server immediately



30
31
32
33
# File 'lib/post.rb', line 30

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

#commentsObject

comments for this post



49
50
51
# File 'lib/post.rb', line 49

def comments
  Comment.find({:post_id => id})
end

#create_comment(attributes = {}) ⇒ Object

create a new comment on the post



24
25
26
27
# File 'lib/post.rb', line 24

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

#create_file(file_path) ⇒ Object

upload a file to a post



36
37
38
39
40
41
# File 'lib/post.rb', line 36

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

#filesObject

persisted files for this post



44
45
46
# File 'lib/post.rb', line 44

def files
  FileAttachment.find({:post_id => id})
end

#flowObject

get the flow for this post



60
61
62
63
# File 'lib/post.rb', line 60

def flow
  return false unless flow_id
  Flow.first({:id => flow_id})
end

permalink to this post



8
9
10
11
12
13
14
# File 'lib/post.rb', line 8

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

#userObject

user for this post



54
55
56
57
# File 'lib/post.rb', line 54

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