Class: Adva::Static::Import::Model::Section

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

Direct Known Subclasses

Blog, Page

Instance Attribute Summary collapse

Attributes inherited from Base

#source

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(source, site = nil, parent = nil) ⇒ Section

Returns a new instance of Section.



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

def initialize(source, site = nil, parent = nil)
  super(source)
  @site = site
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/adva/static/import/model/section.rb', line 6

def parent
  @parent
end

Instance Method Details

#attribute_namesObject



18
19
20
# File 'lib/adva/static/import/model/section.rb', line 18

def attribute_names
  @attribute_names ||= super | [:site_id, :parent_id, :type, :name, :slug]
end

#parent_idObject



38
39
40
# File 'lib/adva/static/import/model/section.rb', line 38

def parent_id
  parent && parent.record.persisted? ? parent.record.id.to_s : nil
end

#recordObject



14
15
16
# File 'lib/adva/static/import/model/section.rb', line 14

def record
  @record ||= model.find_or_initialize_by_slug(source.data.slug)
end

#siteObject



26
27
28
# File 'lib/adva/static/import/model/section.rb', line 26

def site
  @site ||= Site.new(source.path.root)
end

#site_idObject



30
31
32
# File 'lib/adva/static/import/model/section.rb', line 30

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

#typeObject



22
23
24
# File 'lib/adva/static/import/model/section.rb', line 22

def type
  model_name
end