Class: Lookbook::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/parser.rb

Constant Summary collapse

YARDOC_FILE_PATH =
Rails.root.join("tmp/storage/.yardoc").to_s

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
# File 'lib/lookbook/parser.rb', line 7

def initialize(paths)
  @paths = paths.map { |p| "#{p}/**/*preview.rb" }
  YARD::Registry.yardoc_file = YARDOC_FILE_PATH
end

Class Method Details

.define_tagsObject



27
28
29
30
31
32
33
# File 'lib/lookbook/parser.rb', line 27

def define_tags
  YARD::Tags::Library.define_tag("Hidden status", :hidden)
  YARD::Tags::Library.define_tag("Label", :label)
  YARD::Tags::Library.define_tag("Display", :display)
  YARD::Tags::Library.define_tag("Position", :position)
  YARD::Tags::Library.define_tag("ID", :id)
end

Instance Method Details

#get_code_object(path) ⇒ Object



20
21
22
23
24
# File 'lib/lookbook/parser.rb', line 20

def get_code_object(path)
  registry = YARD::RegistryStore.new
  registry.load!(YARDOC_FILE_PATH)
  registry.get(path)
end

#parseObject



12
13
14
15
16
17
18
# File 'lib/lookbook/parser.rb', line 12

def parse
  YARD::Registry.clear
  YARD::Registry.lock_for_writing do
    YARD.parse(@paths)
    YARD::Registry.save(false, YARDOC_FILE_PATH)
  end
end