Class: Post
- Inherits:
-
Flareshow::Resource
- Object
- Flareshow::Resource
- Post
- Extended by:
- Flareshow::Searchable
- Defined in:
- lib/post.rb
Instance Method Summary collapse
-
#build_comment(attributes = {}) ⇒ Object
build a new comment but don’t immediately persist it.
-
#build_file(file_path) ⇒ Object
build a new file object on the client but don’t commit to the server immediately.
-
#comments ⇒ Object
comments for this post.
- #content ⇒ Object
-
#create_comment(attributes = {}) ⇒ Object
create a new comment on the post.
-
#create_file(file_path) ⇒ Object
upload a file to a post.
-
#files ⇒ Object
persisted files for this post.
-
#flow ⇒ Object
get the flow for this post.
-
#permalink(mobile = false) ⇒ Object
permalink to this post.
-
#user ⇒ Object
user for this post.
Methods included from Flareshow::Searchable
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 |
#comments ⇒ Object
comments for this post
54 55 56 57 58 |
# File 'lib/post.rb', line 54 def comments cached = Comment.list_cache comments = cached.select{|c|c.reply_to == id} comments end |
#content ⇒ Object
43 44 45 |
# File 'lib/post.rb', line 43 def content Nokogiri::HTML::Document.new.fragment(get("content")).to_s 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 = [] end |
#files ⇒ Object
persisted files for this post
48 49 50 51 |
# File 'lib/post.rb', line 48 def files cached = FileAttachment.list_cache files = cached.select{|f|f.post_id == id} end |
#flow ⇒ Object
get the flow for this post
68 69 70 71 |
# File 'lib/post.rb', line 68 def flow return false unless flow_id Flow.first({:id => flow_id}) end |
#permalink(mobile = false) ⇒ Object
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 |