Class: TrelloFs::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/trello-fs/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Builder



5
6
7
# File 'lib/trello-fs/builder.rb', line 5

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/trello-fs/builder.rb', line 3

def config
  @config
end

Instance Method Details

#boards_content(repository, boards) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/trello-fs/builder.rb', line 53

def boards_content(repository, boards)
  boards.map do |board|
    board_builder = BoardBuilder.new(repository, board)
    [
      "## [#{board.name}](#{board_builder.relative_path}/README.md)",
      board.lists.map do |list|
        list_builder = ListBuilder.new(board_builder, list)
        "  - [#{list_builder.list_name}](#{list_builder.relative_path}/README.md)"
      end.join("\n")
    ].join("\n\n")
  end.join("\n\n")
end

#buildObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trello-fs/builder.rb', line 9

def build
  repository = Repository.new(@config, self)

  # remove old files from the repo
  RepositoryCleaner.new(repository).clean

  boards = TrelloApi.new(repository).boards
  boards.each do |board|
    BoardBuilder.new(repository, board).build
  end
  LabelsBuilder.new(repository).build
  build_readme(repository, boards)

  # remove old attachments
  AttachmentCleaner.new(repository).remove_old_attachments
end

#build_readme(repository, boards) ⇒ Object



26
27
28
29
30
31
# File 'lib/trello-fs/builder.rb', line 26

def build_readme(repository, boards)
  readme_path = File.join(repository.path, 'README.md')
  File.open(readme_path, 'w') do |file|
    file.write(readme_content(repository, boards))
  end
end

#labels_content(repository) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/trello-fs/builder.rb', line 42

def labels_content(repository)
  return '' unless repository.labels && repository.labels.any?

  repository.labels.values.sort {|a, b| a.name <=> b.name }.
    select {|lbl| lbl.cards.any? }.
    map do |label|
    label_builder = LabelBuilder.new(@repository, label)
    "[`#{label_builder.label_name}`](#{label_builder.relative_path})"
  end.join(' ')
end

#readme_content(repository, boards) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/trello-fs/builder.rb', line 33

def readme_content(repository, boards)
  [
    "# #{repository.title}",
    repository.description,
    labels_content(repository),
    boards_content(repository, boards)
  ].join("\n\n")
end

#trello_api_board(repository) ⇒ Object



66
67
68
# File 'lib/trello-fs/builder.rb', line 66

def trello_api_board(repository)
  Trello::Board.find(repository.board_id)
end