Class: Ubiquitously::Post

Inherits:
Base show all
Defined in:
lib/ubiquitously/models/post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#apply, #debug?

Methods included from SubclassableCallbacks

included, override

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

#categoriesObject

Returns the value of attribute categories.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def categories
  @categories
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def description
  @description
end

#extensionObject

Returns the value of attribute extension.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def extension
  @extension
end

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def format
  @format
end

#pageObject

Returns the value of attribute page.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def page
  @page
end

#postsObject

Returns the value of attribute posts.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def posts
  @posts
end

#tagsObject

Returns the value of attribute tags.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def title
  @title
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def url
  @url
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'lib/ubiquitously/models/post.rb', line 3

def user
  @user
end

Instance Method Details

#inspectObject



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.tags.inspect}>"
end

#new_record?(service, &block) ⇒ Boolean

Returns:

  • (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.tags,
        :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)
  options = services.extract_options!
  postables(*services).map { |post| post.save }
end