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.
703 704 705 706 707 708 |
# File 'lib/brut/cli/apps/scaffold.rb', line 703 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
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
# File 'lib/brut/cli/apps/scaffold.rb', line 713 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
710 |
# File 'lib/brut/cli/apps/scaffold.rb', line 710 def found_routes? = @found_routes |
#routes_existed? ⇒ Boolean
711 |
# File 'lib/brut/cli/apps/scaffold.rb', line 711 def routes_existed? = @routes_existed |