Class: OasRails::OasRoute
- Inherits:
-
Object
- Object
- OasRails::OasRoute
- Defined in:
- lib/oas_rails/oas_route.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#controller_action ⇒ Object
Returns the value of attribute controller_action.
-
#controller_class ⇒ Object
Returns the value of attribute controller_class.
-
#controller_path ⇒ Object
Returns the value of attribute controller_path.
-
#docstring ⇒ Object
Returns the value of attribute docstring.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#rails_route ⇒ Object
Returns the value of attribute rails_route.
-
#source_string ⇒ Object
Returns the value of attribute source_string.
-
#verb ⇒ Object
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
- #controller_path_extractor(controller) ⇒ Object
- #extract_docstring ⇒ Object
- #extract_rails_route_data ⇒ Object
- #extract_source_string ⇒ Object
-
#initialize ⇒ OasRoute
constructor
A new instance of OasRoute.
- #path_params ⇒ Object
Constructor Details
#initialize ⇒ OasRoute
Returns a new instance of OasRoute.
6 |
# File 'lib/oas_rails/oas_route.rb', line 6 def initialize; end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def controller @controller end |
#controller_action ⇒ Object
Returns the value of attribute controller_action.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def controller_action @controller_action end |
#controller_class ⇒ Object
Returns the value of attribute controller_class.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def controller_class @controller_class end |
#controller_path ⇒ Object
Returns the value of attribute controller_path.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def controller_path @controller_path end |
#docstring ⇒ Object
Returns the value of attribute docstring.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def docstring @docstring end |
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def path @path end |
#rails_route ⇒ Object
Returns the value of attribute rails_route.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def rails_route @rails_route end |
#source_string ⇒ Object
Returns the value of attribute source_string.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def source_string @source_string end |
#verb ⇒ Object
Returns the value of attribute verb.
3 4 5 |
# File 'lib/oas_rails/oas_route.rb', line 3 def verb @verb end |
Class Method Details
.new_from_rails_route(rails_route: ActionDispatch::Journey::Route) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/oas_rails/oas_route.rb', line 8 def self.new_from_rails_route(rails_route: ActionDispatch::Journey::Route) instance = new instance.rails_route = rails_route instance.extract_rails_route_data instance end |
Instance Method Details
#controller_path_extractor(controller) ⇒ Object
41 42 43 |
# File 'lib/oas_rails/oas_route.rb', line 41 def controller_path_extractor(controller) Rails.root.join("app/controllers/#{controller}_controller.rb").to_s end |
#extract_docstring ⇒ Object
27 28 29 30 31 |
# File 'lib/oas_rails/oas_route.rb', line 27 def extract_docstring ::YARD::Docstring.parser.parse( controller_class.constantize.instance_method(method).comment.lines.map { |line| line.sub(/^#\s*/, '') }.join ).to_docstring end |
#extract_rails_route_data ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oas_rails/oas_route.rb', line 15 def extract_rails_route_data @controller_action = "#{@rails_route.defaults[:controller].camelize}Controller##{@rails_route.defaults[:action]}" @controller_class = "#{@rails_route.defaults[:controller].camelize}Controller" @controller = @rails_route.defaults[:controller] @controller_path = controller_path_extractor(@rails_route.defaults[:controller]) @method = @rails_route.defaults[:action] @verb = @rails_route.verb @path = Extractors::RouteExtractor.clean_route(@rails_route.path.spec.to_s) @docstring = extract_docstring @source_string = extract_source_string end |
#extract_source_string ⇒ Object
33 34 35 |
# File 'lib/oas_rails/oas_route.rb', line 33 def extract_source_string @controller_class.constantize.instance_method(method).source end |
#path_params ⇒ Object
37 38 39 |
# File 'lib/oas_rails/oas_route.rb', line 37 def path_params @rails_route.path.spec.to_s.scan(/:(\w+)/).flatten.reject! { |e| e == 'format' } end |