Class: Funicular::RouteParser
- Inherits:
-
Object
- Object
- Funicular::RouteParser
- Defined in:
- lib/funicular/route_parser.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#initialize(source_file) ⇒ RouteParser
constructor
A new instance of RouteParser.
- #parse ⇒ Object
Constructor Details
#initialize(source_file) ⇒ RouteParser
Returns a new instance of RouteParser.
7 8 9 10 |
# File 'lib/funicular/route_parser.rb', line 7 def initialize(source_file) @source_file = source_file @routes = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/funicular/route_parser.rb', line 5 def routes @routes end |
Instance Method Details
#parse ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/funicular/route_parser.rb', line 12 def parse return [] unless File.exist?(@source_file) content = File.read(@source_file) lines = content.split("\n") lines.each do |line| # Skip comments and empty lines trimmed = line.strip next if trimmed.empty? || trimmed.start_with?('#') # Parse router.get/post/put/patch/delete lines if trimmed.include?('router.') parse_route_line(trimmed) end end @routes end |