Class: Brut::CLI::Apps::Scaffold::RoutesEditor
- Inherits:
-
Object
- Object
- Brut::CLI::Apps::Scaffold::RoutesEditor
- Defined in:
- lib/brut/cli/apps/scaffold.rb
Instance Method Summary collapse
-
#add_route!(route_code:) ⇒ Object
-
#found_routes? ⇒ Boolean
-
#initialize(app_path:, out:) ⇒ RoutesEditor
constructor
A new instance of RoutesEditor.
-
#routes_existed? ⇒ Boolean
Constructor Details
#initialize(app_path:, out:) ⇒ RoutesEditor
Returns a new instance of RoutesEditor.
619 620 621 622 623 624 |
# File 'lib/brut/cli/apps/scaffold.rb', line 619 def initialize(app_path:,out:) @app_path = app_path @out = out @found_routes = false @routes_existed = false end |
Instance Method Details
#add_route!(route_code:) ⇒ Object
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/brut/cli/apps/scaffold.rb', line 629 def add_route!(route_code:) app_contents = File.read(@app_path).split(/\n/) File.open(@app_path,"w") do |file| in_routes = false app_contents.each do |line| if line =~ /^ routes do\s*$/ in_routes = true end if in_routes && line.include?(route_code) @routes_existed = true end if in_routes && line =~ /^ end\s*$/ if !@routes_existed @out.puts "Inserted route into #{@app_path.relative_path_from(Brut.container.project_root)}" file.puts " #{route_code}" end @found_routes = true in_routes = false end file.puts line end end end |
#found_routes? ⇒ Boolean
626 |
# File 'lib/brut/cli/apps/scaffold.rb', line 626 def found_routes? = @found_routes |
#routes_existed? ⇒ Boolean
627 |
# File 'lib/brut/cli/apps/scaffold.rb', line 627 def routes_existed? = @routes_existed |