Class: Ubiquitously::Post
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#description ⇒ Object
Returns the value of attribute description.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#format ⇒ Object
Returns the value of attribute format.
-
#page ⇒ Object
Returns the value of attribute page.
-
#posts ⇒ Object
Returns the value of attribute posts.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Post
constructor
A new instance of Post.
- #inspect ⇒ Object
- #new_record?(service, &block) ⇒ Boolean
- #postables(*services) ⇒ Object
-
#save(*services) ⇒ Object
create or update.
Methods inherited from Base
Methods included from SubclassableCallbacks
Constructor Details
#initialize(attributes = {}) ⇒ Post
Returns a new instance of Post.
5 6 7 8 9 |
# File 'lib/ubiquitously/models/post.rb', line 5 def initialize(attributes = {}) apply attributes raise 'please pass Post a User' if self.user.blank? self.posts ||= [] end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def categories @categories end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def description @description end |
#extension ⇒ Object
Returns the value of attribute extension.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def extension @extension end |
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def format @format end |
#page ⇒ Object
Returns the value of attribute page.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def page @page end |
#posts ⇒ Object
Returns the value of attribute posts.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def posts @posts end |
#tags ⇒ Object
Returns the value of attribute tags.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/ubiquitously/models/post.rb', line 3 def user @user end |
Instance Method Details
#inspect ⇒ Object
61 62 63 |
# File 'lib/ubiquitously/models/post.rb', line 61 def inspect "#<#{self.class.inspect} @url=#{self.url.inspect} @title=#{self.title.inspect} @description=#{self.description.inspect} @tags=#{self..inspect}>" end |
#new_record?(service, &block) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/ubiquitously/models/post.rb', line 21 def new_record?(service, &block) postables(*service).detect do |post| post.new_record? end end |
#postables(*services) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ubiquitously/models/post.rb', line 27 def postables(*services) services = services.flatten.map(&:to_sym) result = services.map do |service| if service.is_a?(Ubiquitously::Service::Post) service else "Ubiquitously::#{service.to_s.camelize}::Post".constantize.new( :user => self.user, :url => self.url, :title => self.title, :description => self.description, :tags => self., :categories => self.categories, :format => self.format, :extension => self.extension ) end end.uniq self.posts = self.posts.concat(result) self.posts.select { |post| services.include?(post.service.to_sym) } end |
#save(*services) ⇒ Object
create or update
16 17 18 19 |
# File 'lib/ubiquitously/models/post.rb', line 16 def save(*services) = services. postables(*services).map { |post| post.save } end |