Skip to content

Commit 837c67a

Browse files
committed
Add AnnotateRoutes::AnnotationProcessor#execute and AnnotateRoutes::RemovalProcessor#execute
1 parent be64c53 commit 837c67a

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

lib/annotate/annotate_routes.rb

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,14 @@ module AnnotateRoutes
2525
class << self
2626
def do_annotations(options = {})
2727
routes_file = File.join('config', 'routes.rb')
28-
processor = AnnotationProcessor.new(options, routes_file)
29-
if processor.routes_file_exist?
30-
if processor.update
31-
puts "#{routes_file} was annotated."
32-
else
33-
puts "#{routes_file} was not changed."
34-
end
35-
else
36-
puts "#{routes_file} could not be found."
37-
end
28+
result = AnnotationProcessor.execute(options, routes_file)
29+
puts result
3830
end
3931

4032
def remove_annotations(options = {})
4133
routes_file = File.join('config', 'routes.rb')
42-
processor = RemovalProcessor.new(options, routes_file)
43-
if processor.routes_file_exist?
44-
if processor.update
45-
puts "Annotations were removed from #{routes_file}."
46-
else
47-
puts "#{routes_file} was not changed (Annotation did not exist)."
48-
end
49-
else
50-
puts "#{routes_file} could not be found."
51-
end
34+
result = RemovalProcessor.execute(options, routes_file)
35+
puts result
5236
end
5337
end
5438
end

lib/annotate/annotate_routes/annotation_processor.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ module AnnotateRoutes
66
class AnnotationProcessor < BaseProcessor
77
include Helpers
88

9+
# @return [String]
10+
def execute
11+
if routes_file_exist?
12+
if update
13+
"#{routes_file} was annotated."
14+
else
15+
"#{routes_file} was not changed."
16+
end
17+
else
18+
"#{routes_file} could not be found."
19+
end
20+
end
21+
922
private
1023

1124
def header

lib/annotate/annotate_routes/base_processor.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
module AnnotateRoutes
22
class BaseProcessor
3+
class << self
4+
# @param options [Hash]
5+
# @param routes_file [String]
6+
# @return [String]
7+
def execute(options, routes_file)
8+
new(options, routes_file).execute
9+
end
10+
11+
private :new
12+
end
13+
314
def initialize(options, routes_file)
415
@options = options
516
@routes_file = routes_file

lib/annotate/annotate_routes/removal_processor.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
module AnnotateRoutes
44
class RemovalProcessor < BaseProcessor
5+
# @return [String]
6+
def execute
7+
if routes_file_exist?
8+
if update
9+
"Annotations were removed from #{routes_file}."
10+
else
11+
"#{routes_file} was not changed (Annotation did not exist)."
12+
end
13+
else
14+
"#{routes_file} could not be found."
15+
end
16+
end
17+
518
private
619

720
def generate_new_content_array(content, header_position)

0 commit comments

Comments
 (0)