Class: Tomdoccery::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



9
10
11
12
13
# File 'lib/tomdoccery.rb', line 9

def initialize
  @directory = './app/models/'
  @models = Dir.glob('./app/models/*')
  @menu_items = set_menu_items
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



6
7
8
# File 'lib/tomdoccery.rb', line 6

def directory
  @directory
end

Returns the value of attribute menu_items.



5
6
7
# File 'lib/tomdoccery.rb', line 5

def menu_items
  @menu_items
end

#modelsObject (readonly)

Returns the value of attribute models.



7
8
9
# File 'lib/tomdoccery.rb', line 7

def models
  @models
end

Instance Method Details

#blocks(model) ⇒ Object



24
25
26
27
28
29
# File 'lib/tomdoccery.rb', line 24

def blocks(model)
  blocks = parse_model(File.read(@directory + model + '.rb'))
  blocks.map do |b|
    parse_block(b)
  end
end

#parse_block(block) ⇒ Object



35
36
37
# File 'lib/tomdoccery.rb', line 35

def parse_block(block)
  block.match(/(^[ ]?#[ ](Internal:|Public:|Deprecated:)[ ].*?#\n)(^[ ]*#[ ]Examples.*?#\n)(^[ ]*#[ ]Returns.*?\.)(.*)/m) || []
end

#parse_model(file) ⇒ Object



31
32
33
# File 'lib/tomdoccery.rb', line 31

def parse_model(file)
  file.scan(/^[ ]+(#[ ][Internal:|Public:|Deprecated:].*?def[ ].*?$)/m).flatten || []
end

#set_menu_itemsObject



15
16
17
18
19
20
21
22
# File 'lib/tomdoccery.rb', line 15

def set_menu_items
  @models.map do |path|
    a = path.split('/')
    name = a[a.length-1]
    camel = name.gsub!('.rb', '').gsub!(/^[a-z]|_+[a-z]/) { |a| a.upcase }.gsub('_', '')
    { display: camel, link: name.downcase }
  end
end