Module: Rapidoc::YamlParser
- Included in:
- Rapidoc
- Defined in:
- lib/rapidoc/yaml_parser.rb
Overview
This module parse controllers comments to yaml format
Instance Method Summary collapse
-
#extract_actions_info(lines, blocks, file_name) ⇒ Array
Check all blocks and load those that are ‘rapidoc actions block’.
-
#extract_resource_info(lines, blocks, file_name) ⇒ Hash
Check if exist a block with resource information ‘rapidoc resource block’.
Instance Method Details
#extract_actions_info(lines, blocks, file_name) ⇒ Array
Check all blocks and load those that are ‘rapidoc actions block’
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rapidoc/yaml_parser.rb', line 40 def extract_actions_info( lines, blocks, file_name ) info = [] blocks = [] unless blocks blocks.each do |b| if lines[ b[:init] ].include? "=begin action" n_lines = b[:end] - b[:init] - 1 begin info << YAML.load( lines[ b[:init] + 1, n_lines ].join.gsub(/\ *#/, '') ) rescue Exception => e puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]" end end end return info end |
#extract_resource_info(lines, blocks, file_name) ⇒ Hash
Check if exist a block with resource information ‘rapidoc resource block’
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rapidoc/yaml_parser.rb', line 15 def extract_resource_info( lines, blocks, file_name ) blocks ? info = [] : blocks = [] blocks.each.map do |b| if lines[ b[:init] ].include? "=begin resource" n_lines = b[:end] - b[:init] - 1 begin info.push YAML.load( lines[ b[:init] +1, n_lines ].join.gsub(/\ *#/, '') ) rescue Psych::SyntaxError => e puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]" rescue => e puts e end end end info.first ? info.first : {} end |