Class: Doc::Configurator::Paths

Inherits:
Doc::Configurator show all
Defined in:
lib/doc/configurator/paths.rb

Instance Attribute Summary

Attributes inherited from Doc::Configurator

#config, #documentor

Instance Method Summary collapse

Methods inherited from Doc::Configurator

default_config_key, inherited, #initialize

Constructor Details

This class inherits a constructor from Doc::Configurator

Instance Method Details

#configure(update) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/doc/configurator/paths.rb', line 8

def configure(update)
  config.check_options!([], [:glob, :main, :file_list, :title])

  @path_pairs = []
  Array(config[:glob]).map do |glob|
    if glob[0, 1] == '~' && (parts = glob.split(File::SEPARATOR, 2)).length == 2
      FSPath(glob).expand_path.glob.map do |path|
        unexpanded_part = FSPath(parts[0])
        @path_pairs << [path, unexpanded_part / path.relative_path_from(unexpanded_part.expand_path)]
      end
    else
      @path_pairs.concat(FSPath(glob).glob)
    end
  end.flatten

  if @path_pairs.empty?
    raise ConfigError.new(self, "expanding #{config[:glob].join(', ')} gave empty list")
  end

  @main = Array(config[:main])

  if config[:file_list]
    @file_list = config[:file_list]
    case @file_list
    when Proc
      if @file_list.arity != 1
        raise ConfigError.new(self, "proc should have on parameter for instance of FileList")
      end
    when Array
      unless @file_list.all?{ |rule| rule =~ /^\+|-/ }
        raise ConfigError.new(self, "all rules must start with + or -")
      end
    else
      raise ConfigError.new(self, "file_list should be either array in form %w[+a/* -b/*] or proc receiving instance of FileList")
    end
  end

  if @title = config[:title]
    unless @title.is_a?(Proc) && @title.arity == 1
      raise ConfigError.new(self, "title should be an instance of Proc receiving one argument (path)")
    end
  end
end

#tasksObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/doc/configurator/paths.rb', line 52

def tasks
  @path_pairs.map do |pair|
    path, unexpanded_path = pair
    unexpanded_path ||= path
    Dir.chdir(path) do
      paths = nil
      if @file_list
        file_list = FileList.new
        case @file_list
        when Proc
          @file_list.call(file_list)
        when Array
          @file_list.each do |rule|
            file_list.send(rule[0, 1] == '+' ? :include : :exclude, rule[1..-1])
          end
        end
      end

      main = nil
      if @main
        @main.each do |main|
          break if main = Dir[main].first
        end
      end

      builder({
        :title => @title ? @title[unexpanded_path].to_s : "path #{unexpanded_path}",
        :source_dir => path,
        :dir_name => "path.#{unexpanded_path.to_s.gsub('_', '').gsub('/', '_').gsub(/[^a-z0-9\-_]/i, '-')}.#{Digest::SHA1.hexdigest(path.to_s)}",
        :paths => file_list,
        :main => main,
      })
    end
  end
end