Class: Cocoadex::DocSetHelper

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

Overview

Helper for finding and indexing DocSets

Constant Summary collapse

ROOT_PATHS =
[
  '~/Library/Developer/Documentation/DocSets',
  '~/Library/Developer/Shared/Documentation/DocSets',
  '/Applications/Xcode.app/Contents/Developer/Documentation/DocSets',
  '/Applications/Xcode.app/Contents/Developer/Platforms/*/Developer/Documentation/DocSets'
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.data_pathObject



14
15
16
# File 'lib/cocoadex/docset_helper.rb', line 14

def self.data_path
  Cocoadex.config_file("data/docsets.blob")
end

.docset_pathsObject



18
19
20
21
22
23
24
# File 'lib/cocoadex/docset_helper.rb', line 18

def self.docset_paths
  @paths ||= begin
    ROOT_PATHS.map do |path|
      Dir.glob(File.expand_path(path)+'/*/')
    end.flatten
  end
end

.readObject



46
47
48
# File 'lib/cocoadex/docset_helper.rb', line 46

def self.read
  @docsets = Serializer.read(data_path)
end

.search_and_index(paths = docset_paths) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cocoadex/docset_helper.rb', line 26

def self.search_and_index paths=docset_paths
  docsets = []
  paths.map do |path|
    if docset = Parser.parse(path)
      docsets << docset
    end
  end

  if docsets.size > 0
    Tokenizer.persist
    CompletionHelper.generate_tags!
    write(docsets)
  end
  logger.info "Done! #{docsets.size} DocSet#{docsets.size == 1 ? '':'s'} indexed."
end

.write(docsets) ⇒ Object



50
51
52
53
# File 'lib/cocoadex/docset_helper.rb', line 50

def self.write docsets
  @docsets = docsets
  Serializer.write_array(data_path, docsets, :overwrite)
end

Instance Method Details

#indexed_docsetsObject



42
43
44
# File 'lib/cocoadex/docset_helper.rb', line 42

def indexed_docsets
  @docsets ||= Serializer.read(data_path)
end