Class: Funicular::RouteParser

Inherits:
Object
  • Object
show all
Defined in:
lib/funicular/route_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#routesObject (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

#parseObject



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