Class: Timetrap::AutoSheets::YamlCwd

Inherits:
Object
  • Object
show all
Defined in:
lib/timetrap/auto_sheets/yaml_cwd.rb

Overview

auto_sheet_paths

Specify which sheet to automatically use in which directories in with the following format in timetrap.yml:

auto_sheet_paths:

Sheet name: /path/to/directory
More specific sheet: /path/to/directory/that/is/nested
Other sheet:
  - /path/to/first/directory
  - /path/to/second/directory

Note Timetrap will always use the sheet specified in the config file if you are in that directory (or in its tree). To use a different sheet, you must be in a different directory.

Instance Method Summary collapse

Instance Method Details

#sheetObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/timetrap/auto_sheets/yaml_cwd.rb', line 20

def sheet
  auto_sheet = nil
  cwd = "#{Dir.getwd}/"
  most_specific = 0
  Array(Timetrap::Config['auto_sheet_paths']).each do |sheet, dirs|
    Array(dirs).each do |dir|
      if cwd.start_with?(dir) && dir.length > most_specific
        most_specific = dir.length
        auto_sheet = sheet
      end
    end
  end
  auto_sheet
end