Class: AwesomeAnnotate::Route
- Inherits:
-
Thor
- Object
- Thor
- AwesomeAnnotate::Route
- Includes:
- AnnotationBlock, RailsEnvironment, Thor::Actions
- Defined in:
- lib/awesome_annotate/route.rb
Instance Method Summary collapse
- #annotate ⇒ Object
-
#initialize(params = {}) ⇒ Route
constructor
A new instance of Route.
- #remove ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Route
Returns a new instance of Route.
14 15 16 17 18 |
# File 'lib/awesome_annotate/route.rb', line 14 def initialize(params = {}) super() @env_file_path = Pathname.new(params[:env_file_path] || 'config/environment.rb') @route_file_path = Pathname.new(params[:route_file_path] || 'config/routes.rb') end |
Instance Method Details
#annotate ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/awesome_annotate/route.rb', line 21 def annotate raise 'Rails application path is required' unless @env_file_path.exist? load_rails_environment inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes) formatter = ActionDispatch::Routing::ConsoleFormatter::Sheet.new routes = inspector.format(formatter, {}) = parse_routes(routes) raise 'Route file not found' unless @route_file_path.exist? insert_file_before_class(@route_file_path, ) say "annotate routes in #{@route_file_path}" end |
#remove ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/awesome_annotate/route.rb', line 40 def remove raise 'Route file not found' unless @route_file_path.exist? if remove_annotation(file_path: @route_file_path, marker: 'routes') say "remove route annotation in #{@route_file_path}" else say "no route annotation in #{@route_file_path}" end end |