Class: SdocAll::Paths

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Base::ClassMethods

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

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from ClassMethods

common_path

Methods included from Base::ClassMethods

#add_merge_task, #add_task, #base_path, #clear, #docs_path, #inherited, #public_path, #remove_if_present, #short_name, #sources_path, #subclasses, #system, #tasks, #to_document, #used_sources, #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

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
      Dir.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