Class: Trellor::Trellor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#be_verboseObject

Returns the value of attribute be_verbose.



10
11
12
# File 'lib/trellor.rb', line 10

def be_verbose
  @be_verbose
end

Class Method Details

.loggerObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/trellor.rb', line 20

def self.logger
  unless @logger
    file = File.new(logger_filename.to_s, 'a')
    # webapi wasn't logging to the file until it was killed.
    # this causes the logger to flush immediately
    file.sync = true
    @logger = Logger.new file
  end
  @logger
end

.logger_filenameObject



31
32
33
34
35
36
# File 'lib/trellor.rb', line 31

def self.logger_filename
  dirpath = Pathname.new(ENV['HOME']) + '.config/trellor'
  dirpath.mkdir unless dirpath.directory?
  filename = 'log'
  dirpath + filename
end

.singletonObject



12
13
14
15
16
17
18
# File 'lib/trellor.rb', line 12

def self.singleton
  unless @singleton
    puts 'getting singleton'
    @singleton = self.new
  end
  @singleton
end

Instance Method Details

#archive_card(board_name, list_name, name) ⇒ Object



62
63
64
65
# File 'lib/trellor.rb', line 62

def archive_card(board_name, list_name, name)
  card = find_card(board_name, list_name, name)
  card.close!
end

#board_namesObject

trellor interface queries ###############



45
46
47
# File 'lib/trellor.rb', line 45

def board_names
  boards.collect{ |board| board.name }.sort_by{|name| name.downcase}
end

#boardsObject

private queries #################



70
71
72
73
# File 'lib/trellor.rb', line 70

def boards
  verbose_log('getting boards') unless @boards
  @boards ||= user.boards.select{ |b| !b.closed? }
end

#boards=(boards) ⇒ Object



74
75
76
# File 'lib/trellor.rb', line 74

def boards=(boards)
  @boards = boards
end

#card_names(board_name, list_name) ⇒ Object



51
52
53
# File 'lib/trellor.rb', line 51

def card_names(board_name, list_name)
  find_list(board_name, list_name).cards.collect{ |card| card.name }
end

#cards(board_name, list_name) ⇒ Object



92
93
94
95
# File 'lib/trellor.rb', line 92

def cards(board_name, list_name)
  verbose_log('       getting cards for', board_name, list_name)
  find_list(board_name, list_name).cards
end

#create_card(board_name, list_name, name, descript = nil) ⇒ Object



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

def create_card(board_name, list_name, name, descript=nil)
  card = Trello::Card.new
  card.client = client
  card.list_id = find_list(board_name, list_name).id
  card.name = name
  card.desc = descript if descript
  card.save
end

#find_board(name) ⇒ Object



78
79
80
81
82
83
# File 'lib/trellor.rb', line 78

def find_board(name)
  boards   # to get verbose log ordering correct
  verbose_log('getting board', name)
  name = Regexp.new(name, Regexp::IGNORECASE)
  boards.find{ |board| name.match(board.name) }
end

#find_card(board_name, list_name, card_name) ⇒ Object



97
98
99
100
101
102
# File 'lib/trellor.rb', line 97

def find_card(board_name, list_name, card_name)
  this_list = find_list(board_name, list_name)
  verbose_log('   getting card', board_name, list_name, card_name)
  name = Regexp.new(card_name, Regexp::IGNORECASE)
  this_list.cards.find{ |card| name.match(card.name) }
end

#find_list(board_name, list_name) ⇒ Object



85
86
87
88
89
90
# File 'lib/trellor.rb', line 85

def find_list(board_name, list_name)
  this_board = find_board(board_name)
  verbose_log('   getting list', board_name, list_name)
  name = Regexp.new(list_name, Regexp::IGNORECASE)
  this_board.lists.find{ |list| name.match(list.name) }
end

#list_names(board_name) ⇒ Object



48
49
50
# File 'lib/trellor.rb', line 48

def list_names(board_name)
  find_board(board_name).lists.collect{ |list| list.name }.sort_by{|name| name.downcase}
end

#loggerObject



38
39
40
# File 'lib/trellor.rb', line 38

def logger
  self.class.logger
end