Class: Tomdoccery::Base
- Inherits:
-
Object
- Object
- Tomdoccery::Base
- Defined in:
- lib/tomdoccery.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#menu_items ⇒ Object
readonly
Returns the value of attribute menu_items.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
Instance Method Summary collapse
- #blocks(model) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #parse_block(block) ⇒ Object
- #parse_model(file) ⇒ Object
- #set_menu_items ⇒ Object
Constructor Details
#initialize ⇒ Base
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 = end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
6 7 8 |
# File 'lib/tomdoccery.rb', line 6 def directory @directory end |
#menu_items ⇒ Object (readonly)
Returns the value of attribute menu_items.
5 6 7 |
# File 'lib/tomdoccery.rb', line 5 def @menu_items end |
#models ⇒ Object (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_items ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/tomdoccery.rb', line 15 def @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 |