Class: Adva::Static::Import::Model::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/adva/static/import/model/post.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#source

Instance Method Summary collapse

Methods inherited from Base

#attribute?, #attribute_value, #attributes, #model, #model_name, #updated_record

Constructor Details

#initialize(source, section = nil) ⇒ Post

Returns a new instance of Post.



10
11
12
13
# File 'lib/adva/static/import/model/post.rb', line 10

def initialize(source, section = nil)
  super(source)
  @section = section
end

Instance Attribute Details

#sectionObject (readonly)

Returns the value of attribute section.



8
9
10
# File 'lib/adva/static/import/model/post.rb', line 8

def section
  @section
end

Instance Method Details

#attribute_namesObject



24
25
26
# File 'lib/adva/static/import/model/post.rb', line 24

def attribute_names
  @attribute_names ||= (super | [:site_id, :section_id, :title, :body, :slug, :published_at, :filter]) - [:categories]
end

#categoriesObject



44
45
46
# File 'lib/adva/static/import/model/post.rb', line 44

def categories
  @categories ||= source.data.categories.map { |name| Category.find_or_create_by_name(name, :section_id => section.record.id) }
end

#recordObject



20
21
22
# File 'lib/adva/static/import/model/post.rb', line 20

def record
  @record ||= ::Post.by_permalink(*permalink).first || ::Post.new
end

#section_idObject



40
41
42
# File 'lib/adva/static/import/model/post.rb', line 40

def section_id
  section ? section.record.id.to_s : nil
end

#siteObject



28
29
30
# File 'lib/adva/static/import/model/post.rb', line 28

def site
  section.try(:site)
end

#site_idObject



32
33
34
# File 'lib/adva/static/import/model/post.rb', line 32

def site_id
  site ? site.record.id.to_s : nil
end

#update!Object



15
16
17
18
# File 'lib/adva/static/import/model/post.rb', line 15

def update!
  super
  record.update_attributes!(:categories => categories)
end