Class: Adva::Static::Import::Model::Site

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

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?, #load, #model, #path, #site_id, #slug, #updated_at, #updated_record

Constructor Details

#initialize(root) ⇒ Site

Returns a new instance of Site.



12
13
14
# File 'lib/adva/static/import/model/site.rb', line 12

def initialize(root)
  super(Source.new('', root))
end

Class Method Details

.recognize(sources) ⇒ Object



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

def recognize(sources)
  sources.map { |source| new(sources.delete(source).root) if source.path == 'site' }.compact
end

Instance Method Details

#accountObject



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

def 
  @account ||= ::Account.first || ::Account.new
end

#attribute_namesObject



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

def attribute_names
  @attribute_names ||= [:account, :host, :name, :title, :sections_attributes]
end

#hostObject



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

def host
  @host ||= File.basename(source.root)
end

#loadableObject



50
51
52
# File 'lib/adva/static/import/model/site.rb', line 50

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

#nameObject



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

def name
  @name ||= host
end

#recordObject



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

def record
  @record ||= model.find_or_initialize_by_host(host)
end

#sectionsObject



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

def sections
  @sections ||= Section.recognize(source.files).tap do |sections|
    sections << Page.new(Source.new('index', source.root).find_or_self) if sections.empty?
  end
end

#sections_attributesObject



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

def sections_attributes
  sections.map(&:attributes)
end

#titleObject



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

def title
  @title ||= name
end