Class: Adva::Static::Import::Model::Site
- Inherits:
-
Base
- Object
- Base
- Adva::Static::Import::Model::Site
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.
14
15
16
|
# File 'lib/adva/static/import/model/site.rb', line 14
def initialize(root)
super(Source.new('', root))
end
|
Class Method Details
.recognize(sources) ⇒ Object
9
10
11
|
# File 'lib/adva/static/import/model/site.rb', line 9
def recognize(sources)
sources.map { |source| new(sources.delete(source).root) if source.path == 'site' }.compact
end
|
Instance Method Details
#account ⇒ Object
38
39
40
|
# File 'lib/adva/static/import/model/site.rb', line 38
def account
@account ||= ::Account.first || ::Account.new
end
|
#attribute_names ⇒ Object
18
19
20
|
# File 'lib/adva/static/import/model/site.rb', line 18
def attribute_names
@attribute_names ||= [:account, :host, :name, :title, :sections_attributes]
end
|
#host ⇒ Object
26
27
28
|
# File 'lib/adva/static/import/model/site.rb', line 26
def host
@host ||= File.basename(source.root)
end
|
#loadable ⇒ Object
52
53
54
|
# File 'lib/adva/static/import/model/site.rb', line 52
def loadable
@loadable ||= Source.new('site', source.root).find_or_self.full_path
end
|
#name ⇒ Object
30
31
32
|
# File 'lib/adva/static/import/model/site.rb', line 30
def name
@name ||= host
end
|
#record ⇒ Object
22
23
24
|
# File 'lib/adva/static/import/model/site.rb', line 22
def record
@record ||= model.find_or_initialize_by_host(host)
end
|
#sections ⇒ Object
46
47
48
49
50
|
# File 'lib/adva/static/import/model/site.rb', line 46
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_attributes ⇒ Object
42
43
44
|
# File 'lib/adva/static/import/model/site.rb', line 42
def sections_attributes
sections.map(&:attributes)
end
|
#title ⇒ Object
34
35
36
|
# File 'lib/adva/static/import/model/site.rb', line 34
def title
@title ||= name
end
|