Class: Rapidoc::ControllerExtractor
- Inherits:
-
Object
- Object
- Rapidoc::ControllerExtractor
- Defined in:
- lib/rapidoc/controller_extractor.rb
Overview
This class open controller file and get all documentation blocks. Lets us check if any of this blocks is a ‘rapidoc` block and return it using `json` format.
Rapidoc blocks must:
-
have YAML format
-
begin with ‘#=begin action` for actions description
-
begin with ‘#=begin resource` for resource description
-
end with ‘#=end`
Instance Method Summary collapse
- #get_action_info(action) ⇒ Object
- #get_actions_info ⇒ Object
- #get_controller_info ⇒ Object
- #get_resource_info ⇒ Object
-
#initialize(controller_file) ⇒ ControllerExtractor
constructor
A new instance of ControllerExtractor.
Constructor Details
#initialize(controller_file) ⇒ ControllerExtractor
Returns a new instance of ControllerExtractor.
16 17 18 19 20 21 22 |
# File 'lib/rapidoc/controller_extractor.rb', line 16 def initialize( controller_file ) lines = IO.readlines( controller_dir( controller_file ) ) blocks = extract_blocks( lines ) @resource_info = YamlParser.extract_resource_info( lines, blocks, controller_file ) @actions_info = YamlParser.extract_actions_info( lines, blocks, controller_file ) end |
Instance Method Details
#get_action_info(action) ⇒ Object
28 29 30 |
# File 'lib/rapidoc/controller_extractor.rb', line 28 def get_action_info( action ) @actions_info.select{ |info| info['action'] == action.to_s }.first end |
#get_actions_info ⇒ Object
24 25 26 |
# File 'lib/rapidoc/controller_extractor.rb', line 24 def get_actions_info @actions_info end |
#get_controller_info ⇒ Object
36 37 38 |
# File 'lib/rapidoc/controller_extractor.rb', line 36 def get_controller_info { "description" => @resource_info["description"], "actions" => @actions_info } end |
#get_resource_info ⇒ Object
32 33 34 |
# File 'lib/rapidoc/controller_extractor.rb', line 32 def get_resource_info @resource_info end |