Module: MarkupModel::ClassMethods

Defined in:
lib/markup_model.rb

Instance Method Summary collapse

Instance Method Details

#markup_model_cleanupObject



21
22
23
24
25
26
27
# File 'lib/markup_model.rb', line 21

def markup_model_cleanup
  ids = Set.new markup_model_files.map(&:id)

  all.each do |model|
    model.destroy unless ids.include?(model.id.to_s)
  end
end

#markup_model_filesObject



29
30
31
32
33
# File 'lib/markup_model.rb', line 29

def markup_model_files
  Dir.glob("#{MarkupModel.config.content_directory}/#{model_name.plural}/*.md").map do |file|
    ModelFile.new(file)
  end
end

#markup_model_reloadObject



35
36
37
38
# File 'lib/markup_model.rb', line 35

def markup_model_reload
  markup_model_cleanup
  markup_model_update
end

#markup_model_updateObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/markup_model.rb', line 40

def markup_model_update
  markup_model_files.each do |file|
    model = find_by_id(file.id) || new.tap { |m| m.id = file.id }
    model.id = file.id
    model.content = file.content
    file.attributes.each do |k,v|
      model.public_send("#{k}=", v)
    end
    model.save!
  end
end