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:, stdout:) ⇒ RoutesEditor
constructor
A new instance of RoutesEditor.
-
#routes_existed? ⇒ Boolean
Constructor Details
#initialize(app_path:, stdout:) ⇒ RoutesEditor
Returns a new instance of RoutesEditor.
711 712 713 714 715 716 |
# File 'lib/brut/cli/apps/scaffold.rb', line 711 def initialize(app_path:,stdout:) @app_path = app_path @stdout = stdout @found_routes = false @routes_existed = false end |
Instance Method Details
#add_route!(route_code:) ⇒ Object
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'lib/brut/cli/apps/scaffold.rb', line 721 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 @stdout.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
718 |
# File 'lib/brut/cli/apps/scaffold.rb', line 718 def found_routes? = @found_routes |
#routes_existed? ⇒ Boolean
719 |
# File 'lib/brut/cli/apps/scaffold.rb', line 719 def routes_existed? = @routes_existed |