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

Attributes inherited from Base

#source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, #==, #attribute_name?, #attributes, #body, #column_name?, #initialize, #load, #model, #site_id, #updated_at, #updated_record

Constructor Details

This class inherits a constructor from Adva::Static::Import::Model::Base

Class Method Details

.recognize(sources) ⇒ Object



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

def recognize(sources)
  types.map { |type| type.recognize(sources) }.flatten.compact.sort
end

.typesObject



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

def types
  [Blog, Page]
end

Instance Method Details

#attribute_namesObject



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

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

#loadableObject



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

def loadable
  @loadable ||= source.root? ? Source.new('index', source.root).find_or_self.full_path : source.full_path
end

#nameObject



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

def name
  @name ||= source.root? ? 'Home' : source.basename.titleize
end

#pathObject



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

def path
  @path ||= source.root? ? slug : super
end

#recordObject



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

def record
  @record ||= site.send(model.name.underscore.pluralize).find_or_initialize_by_path(path)
end

#siteObject



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

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

#slugObject



36
37
38
# File 'lib/adva/static/import/model/section.rb', line 36

def slug
  @slug ||= source.root? ? SimpleSlugs::Slug.new(name) : super
end

#typeObject



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

def type
  model.name
end