Class: DocumentList

Inherits:
Object
  • Object
show all
Defined in:
lib/document.rb

Overview

Module API

Instance Method Summary collapse

Constructor Details

#initialize(paths, config) ⇒ DocumentList

Public



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/document.rb', line 11

def initialize(paths, config)
  @documents = []
  if paths.empty?
    for item in config['documents']
      paths.push(item['main'])
    end
  end
  for path in !paths.empty? ? paths : ['README.md']
    main_path = path
    edit_path = nil
    sync_path = nil
    for item in config['documents']
      if path == item['main']
        edit_path = item.fetch('edit', nil)
        sync_path = item.fetch('sync', nil)
        break
      end
    end
    document = Document.new(main_path, edit_path:edit_path, sync_path:sync_path)
    @documents.push(document)
  end
end

Instance Method Details

#editObject



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

def edit()
  for document in @documents
    document.edit()
  end
end

#syncObject



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

def sync()
  success = true
  for document in @documents
    valid = document.test(sync:true)
    success = success && valid
    if valid
      document.sync()
    end
  end
  return success
end

#test(exit_first: false) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/document.rb', line 52

def test(exit_first:false)
  success = true
  for document, index in @documents.each_with_index
    number = index + 1
    valid = document.test(exit_first:exit_first)
    success = success && valid
    print_message(nil, (number < @documents.length ? 'separator' : 'blank'))
  end
  return success
end