Class: SdocAll::Paths

Inherits:
Base
  • Object
show all
Defined in:
lib/sdoc_all/parts/paths.rb

Constant Summary

Constants inherited from Base

Base::BASE_PATH, Base::DOCS_PATH, Base::PUBLIC_PATH

Instance Attribute Summary

Attributes inherited from Base

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

add_merge_task, add_task, base_path, chdir, clear, dirs, docs_path, dry_run!, dry_run?, entries, inherited, output_for_verbose_level, public_path, remove_if_present, short_name, sources_path, subclasses, system, tasks, to_document, used_sources, verbose_level, verbose_level=, with_env

Constructor Details

#initialize(raw_config) ⇒ Paths

Returns a new instance of Paths.



3
4
5
6
7
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
51
52
# File 'lib/sdoc_all/parts/paths.rb', line 3

def initialize(raw_config)
  raw_config = [raw_config] unless raw_config.is_a?(Array)

  errors = []
  raw_config.each do |raw_entry|
    begin
      raw_entries = case raw_entry
      when Hash
        [raw_entry]
      when String
        Dir[File.expand_path(raw_entry)].map{ |path| {:root => path} }
      else
        raise_unknown_options_if_not_blank!(raw_entry)
      end

      raw_entries.each do |entry|
        begin
          entry.symbolize_keys!

          unless entry[:root].present?
            raise ConfigError.new("specify what to document")
          end

          root = Pathname.new(entry.delete(:root)).expand_path

          unless root.exist?
            raise ConfigError.new("path #{root} does not exist")
          end

          paths = entry.delete(:paths)
          paths = [paths] if paths && !paths.is_a?(Array)

          entries << {
            :root => root,
            :main => entry.delete(:main),
            :paths => paths,
          }
          raise_unknown_options_if_not_blank!(entry)
        rescue ConfigError => e
          errors << e
        end
      end
    rescue ConfigError => e
      errors << e
    end
  end
  unless errors.empty?
    raise ConfigError.new(errors.join("\n"))
  end
end

Class Method Details

.common_path(paths) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sdoc_all/parts/paths.rb', line 95

def common_path(paths)
  common = nil
  paths.each do |path|
    if common ||= path
      unless path.to_s.starts_with?(common.to_s)
        path.ascend do |path_part|
          if common.to_s.starts_with?(path_part.to_s)
            common = path_part
            break
          end
        end
      end
    end
  end
  common = common.parent if common
end

Instance Method Details

#add_tasks(options = {}) ⇒ Object



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/sdoc_all/parts/paths.rb', line 54

def add_tasks(options = {})
  common_path = self.class.common_path(entries.map{ |entry| entry[:root] })

  entries.each do |entry|
    path = entry[:root]

    task_options = {
      :src_path => path,
      :doc_path => "paths.#{path.relative_path_from(common_path).to_s.gsub('/', '.')}",
      :title => "paths: #{path.relative_path_from(common_path)}"
    }
    task_options[:main] = entry[:main] if entry[:main]

    if entry[:paths]
      paths = FileList.new
      Base.chdir(path) do
        entry[:paths].each do |glob|
          m = /^([+-]?)(.*)$/.match(glob)
          if m[1] == '-'
            paths.exclude(m[2])
          else
            paths.include(m[2])
          end
        end
        paths.resolve
      end

      task_options[:paths] = paths.to_a
    end

    Base.add_task(task_options)
  end
end