File tree Expand file tree Collapse file tree 11 files changed +152
-101
lines changed
Expand file tree Collapse file tree 11 files changed +152
-101
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,6 @@ Layout/MultilineMethodCallIndentation:
2424Layout/EmptyLinesAroundAccessModifier :
2525 EnforcedStyle : only_before
2626
27- Layout/LineLength :
28- Exclude :
29- - " scripts/generate_fixture.rb"
30-
3127Lint/SuppressedException :
3228 Exclude :
3329 - " test/**/*"
Original file line number Diff line number Diff line change 1- FROM ruby:2.6.6-alpine3.12
1+ FROM amazon/aws-lambda-ruby
22
3- RUN apk update && apk upgrade && \
4- apk add --no-cache bash git openssh && \
5- apk add build-base gcc wget git
3+ RUN yum install -y make gcc
64
7- RUN gem install bundler -v 2.1.4
5+ WORKDIR /var/task
86
9- WORKDIR /opt/snippet-extractor
7+ RUN gem install json -v '2.3.1'
108
119COPY . .
1210
13- RUN bundle install
11+ RUN bundle config set deployment 'true' && \
12+ bundle config set without 'development test' && \
13+ bundle install
1414
15- ENTRYPOINT [ "sh" , "/opt/snippet-extractor/bin/run.sh" ]
15+ CMD [ "source.SnippetExtractor.process_request." ]
Original file line number Diff line number Diff line change @@ -13,6 +13,5 @@ group :test do
1313 gem 'minitest' , '~> 5.10' , '!= 5.10.2'
1414 gem 'minitest-stub-const'
1515 gem 'mocha'
16- gem 'pry'
1716 gem 'simplecov' , '~> 0.17.0'
1817end
Original file line number Diff line number Diff line change 11GEM
22 remote: https://rubygems.org/
33 specs:
4- coderay (1.1.3 )
54 docile (1.3.2 )
65 json (2.3.1 )
76 mandate (0.3.0 )
8- method_source (1.0.0 )
97 minitest (5.14.2 )
108 minitest-stub-const (0.6 )
119 mocha (1.11.2 )
12- pry (0.13.1 )
13- coderay (~> 1.1 )
14- method_source (~> 1.0 )
1510 rake (13.0.1 )
1611 simplecov (0.17.1 )
1712 docile (~> 1.1 )
@@ -28,7 +23,6 @@ DEPENDENCIES
2823 minitest (~> 5.10 , != 5.10.2 )
2924 minitest-stub-const
3025 mocha
31- pry
3226 rake
3327 simplecov (~> 0.17.0 )
3428
Original file line number Diff line number Diff line change 55loader . setup
66
77module SnippetExtractor
8- def self . extract ( language_slug , submission_path , output_path )
9- submission_pathname = Pathname . new ( submission_path )
10- output_pathname = Pathname . new ( output_path )
11-
12- #ExtractSnippet.(exercise_slug, submission_pathname, output_pathname)
8+ def self . process_request ( event :, context :)
9+ ProcessRequest . ( event , context )
1310 end
1411end
Original file line number Diff line number Diff line change 88 lines . drop_while do |line |
99 naked_line = line . strip
1010 next true if naked_line . empty?
11- next true if ignore_list . any? { |ignore | naked_line . start_with? ( ignore ) }
11+ next true if ignore_list . any? { |ignore | naked_line . start_with? ( ignore ) }
12+
1213 false
1314 end [ 0 ...10 ] . join
1415 end
@@ -20,7 +21,7 @@ def lines
2021 memoize
2122 def ignore_list
2223 slug = language . to_s . gsub ( /[^a-z0-9-]/ , '' )
23- File . read ( File . expand_path ( "../../languages/#{ slug } .txt" , __FILE__ ) ) . lines . map ( &:rstrip )
24+ File . read ( File . expand_path ( "../../languages/#{ slug } .txt" , __FILE__ ) ) . lines . map ( &:rstrip )
2425 end
2526 end
2627end
Original file line number Diff line number Diff line change 1+ module SnippetExtractor
2+ class ProcessRequest
3+ include Mandate
4+
5+ initialize_with :event , :context
6+
7+ def call
8+ p event
9+ p context
10+ snippet = ExtractSnippet . ( source_code , language )
11+
12+ {
13+ statusCode : 200 ,
14+ headers : {
15+ 'Content-Length' : snippet . bytesize ,
16+ 'Content-Type' : 'application/plain; charset=utf-8' ,
17+ 'Content-disposition' : 'attachment;snippet.txt'
18+ } ,
19+ isBase64Encoded : false ,
20+ body : snippet
21+ }
22+ end
23+
24+ def source_code
25+ event [ 'source_code' ]
26+ end
27+
28+ def language
29+ event [ 'language' ]
30+ end
31+ end
32+ end
Original file line number Diff line number Diff line change @@ -4,59 +4,59 @@ module SnippetExtractor
44 module Languages
55 class RubyTest < Minitest ::Test
66 def test_strips_correctly
7- code = <<-CODE
8- # This is a file
9- # With some comments in it
10-
11- # And a blank line ⬆️
12- # It has some requires like this:
13- require 'json'
7+ code = <<~CODE
8+ # This is a file
9+ # With some comments in it
1410
15- # And then eventually the code
16- class TwoFer
17- ...
18- end
11+ # And a blank line ⬆️
12+ # It has some requires like this:
13+ require 'json'
14+
15+ # And then eventually the code
16+ class TwoFer
17+ ...
18+ end
1919 CODE
2020
21- expected = <<- CODE
22- class TwoFer
23- ...
24- end
21+ expected = <<~ CODE
22+ class TwoFer
23+ ...
24+ end
2525 CODE
2626
2727 assert_equal expected , ExtractSnippet . ( code , :ruby )
2828 end
2929
3030 def test_extracts_first_10
31- code = <<- CODE
32- # Here is some code
33- class TwoFer
34- Line 2
35- Line 3
36- Line 4
37- Line 5
38- Line 6
39- Line 7
40- Line 8
41- Line 9
42- Line 10
43- Line 11
44- Line 12
45- Line 13
46- end
31+ code = <<~ CODE
32+ # Here is some code
33+ class TwoFer
34+ Line 2
35+ Line 3
36+ Line 4
37+ Line 5
38+ Line 6
39+ Line 7
40+ Line 8
41+ Line 9
42+ Line 10
43+ Line 11
44+ Line 12
45+ Line 13
46+ end
4747 CODE
4848
49- expected = <<- CODE
50- class TwoFer
51- Line 2
52- Line 3
53- Line 4
54- Line 5
55- Line 6
56- Line 7
57- Line 8
58- Line 9
59- Line 10
49+ expected = <<~ CODE
50+ class TwoFer
51+ Line 2
52+ Line 3
53+ Line 4
54+ Line 5
55+ Line 6
56+ Line 7
57+ Line 8
58+ Line 9
59+ Line 10
6060 CODE
6161
6262 assert_equal expected , ExtractSnippet . ( code , :ruby )
Original file line number Diff line number Diff line change @@ -4,35 +4,34 @@ module SnippetExtractor
44 module Languages
55 class CsharpTest < Minitest ::Test
66 def test_full_example
7- code = <<- CODE
8- /* Welcome to my program
9- * It is very cool!!
10- */
7+ code = <<~ CODE
8+ /* Welcome to my program
9+ * It is very cool!!
10+ */
1111
12- using something.baddass
12+ using something.baddass
1313
14- // I love C#!!
14+ // I love C#!!
1515
16- public static class Grains
17- {
18- public static double Square(int i) => Math.Pow(2, i - 1);
16+ public static class Grains
17+ {
18+ public static double Square(int i) => Math.Pow(2, i - 1);
1919
20- public static double Total() => Enumerable.Range(1, 64).Select(Square).Sum();
21- }
20+ public static double Total() => Enumerable.Range(1, 64).Select(Square).Sum();
21+ }
2222 CODE
2323
24- expected = <<- CODE
25- public static class Grains
26- {
27- public static double Square(int i) => Math.Pow(2, i - 1);
24+ expected = <<~ CODE
25+ public static class Grains
26+ {
27+ public static double Square(int i) => Math.Pow(2, i - 1);
2828
29- public static double Total() => Enumerable.Range(1, 64).Select(Square).Sum();
30- }
29+ public static double Total() => Enumerable.Range(1, 64).Select(Square).Sum();
30+ }
3131 CODE
3232
3333 assert_equal expected , ExtractSnippet . ( code , :csharp )
3434 end
3535 end
3636 end
3737end
38-
Original file line number Diff line number Diff line change @@ -4,24 +4,24 @@ module SnippetExtractor
44 module Languages
55 class RubyTest < Minitest ::Test
66 def test_full_example
7- code = <<-CODE
8- # This is a file
9- # With some comments in it
10-
11- # And a blank line ⬆️
12- # It has some requires like this:
13- require 'json'
7+ code = <<~CODE
8+ # This is a file
9+ # With some comments in it
1410
15- # And then eventually the code
16- class TwoFer
17- ...
18- end
11+ # And a blank line ⬆️
12+ # It has some requires like this:
13+ require 'json'
14+
15+ # And then eventually the code
16+ class TwoFer
17+ ...
18+ end
1919 CODE
2020
21- expected = <<- CODE
22- class TwoFer
23- ...
24- end
21+ expected = <<~ CODE
22+ class TwoFer
23+ ...
24+ end
2525 CODE
2626
2727 assert_equal expected , ExtractSnippet . ( code , :ruby )
You can’t perform that action at this time.
0 commit comments