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.
694 695 696 697 698 699 |
# File 'lib/brut/cli/apps/scaffold.rb', line 694 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
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/brut/cli/apps/scaffold.rb', line 704 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
701 |
# File 'lib/brut/cli/apps/scaffold.rb', line 701 def found_routes? = @found_routes |
#routes_existed? ⇒ Boolean
702 |
# File 'lib/brut/cli/apps/scaffold.rb', line 702 def routes_existed? = @routes_existed |