Class: Adva::Static::Import::Model::Base

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

Direct Known Subclasses

Post, Section, Site

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Base

Returns a new instance of Base.



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

def initialize(source)
  @source = source
  load
end

Instance Attribute Details

#attribute_namesObject (readonly)

Returns the value of attribute attribute_names.



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

def attribute_names
  @attribute_names
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#<=>(other) ⇒ Object



71
72
73
# File 'lib/adva/static/import/model/base.rb', line 71

def <=>(other)
  source <=> other.source
end

#==(other) ⇒ Object



67
68
69
# File 'lib/adva/static/import/model/base.rb', line 67

def ==(other)
  source == other
end

#attribute_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/adva/static/import/model/base.rb', line 21

def attribute_name?(name)
  attribute_names.include?(name.to_sym)
end

#attributesObject



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

def attributes
  attributes = attribute_names.map { |name| [name, self.send(name)] unless self.send(name).nil? }
  attributes = Hash[*attributes.compact.flatten_once]
  record && record.id ? attributes.merge(:id => record.id.to_s) : attributes
end

#bodyObject



49
50
51
# File 'lib/adva/static/import/model/base.rb', line 49

def body
  @body || ''
end

#column_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/adva/static/import/model/base.rb', line 25

def column_name?(name)
  model.column_names.include?(name.to_s)
end

#loadObject



61
62
63
64
65
# File 'lib/adva/static/import/model/base.rb', line 61

def load
  if loadable.exist?
    format = Format.for(loadable) and format.load(self)
  end
end

#loadableObject



57
58
59
# File 'lib/adva/static/import/model/base.rb', line 57

def loadable
  @loadable ||= source.full_path
end

#modelObject



33
34
35
# File 'lib/adva/static/import/model/base.rb', line 33

def model
  self.class.name.demodulize.constantize
end

#pathObject



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

def path
  source.path
end

#site_idObject



37
38
39
# File 'lib/adva/static/import/model/base.rb', line 37

def site_id
  site.id.to_s
end

#slugObject



41
42
43
# File 'lib/adva/static/import/model/base.rb', line 41

def slug
  source.basename
end

#updated_atObject



53
54
55
# File 'lib/adva/static/import/model/base.rb', line 53

def updated_at
  source.mtime
end

#updated_recordObject



29
30
31
# File 'lib/adva/static/import/model/base.rb', line 29

def updated_record
  record.tap { |record| record.attributes = attributes }
end