scoreboard_rubywarrior 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5aad92b5e37eed7e9b81747d417bbfaa3e409df
4
- data.tar.gz: 9dad9dd4d8e7db2aecce211c610feb9e6e34c021
3
+ metadata.gz: e3288d2d9f05ea8ed21c88a5e5214d9bcd47c313
4
+ data.tar.gz: 67442f5ffa316e14863e0cd1b6df643ae97bad3e
5
5
  SHA512:
6
- metadata.gz: 804e16624cbd2a982900fec415c4cd8c770c1fb24f33cb81d726edc9f518e6d5aeac62c8d41a272251ff4a85391702e339ad6ad9d110d4b17e6b7c1dbd4bc3df
7
- data.tar.gz: bc3cd69417e8f185498fab9faf81e8bf9454fd64c931fc17c3a6aaf7f8152053d6d7536953afddbf275f47956fb6b4d0c18fa52615c73b8844ad02762e0ee01c
6
+ metadata.gz: 7ac7ab7252babc0175bdb070efc322d1b1fb4580804df781aa276d2bff2e23bc562f3b004339bb37843f035d2256b22584af46c168d566d6545a847c8bbef0c1
7
+ data.tar.gz: 58ba749ae478dbf048f3862d5bbee400bf08dbfc2cf04c8d9d11e2f696d7506224d8fb4c3aa154983dcfe7861c32e6343cf77c92d9ea71c996bd0812a9bf150b
@@ -0,0 +1,41 @@
1
+ module ScoreboardRubywarrior
2
+ class Concatenator
3
+ def initialize(path)
4
+ @path = path
5
+ @contents_of_files = ""
6
+ end
7
+
8
+ def concatenate
9
+ raise ScoreboardRubywarrior::InvalidPlayerDirectory, "player.rb not present" unless player_file_exists?
10
+ all_ruby_files.each do |file|
11
+ append_file(file)
12
+ end
13
+
14
+ contents_of_files
15
+ end
16
+
17
+
18
+ private
19
+
20
+ attr_reader :path
21
+ attr_accessor :contents_of_files
22
+
23
+ def all_ruby_files
24
+ Dir["#{path}/**/**/*.rb"]
25
+ end
26
+
27
+ def append_file(file)
28
+ file_name = Pathname.new(file).basename
29
+ file_contents = File.read(file)
30
+
31
+ contents_of_files << "#" << file_name.to_s << "\n"
32
+ contents_of_files << "#---------------" << "\n"
33
+ contents_of_files << file_contents << "\n"
34
+ contents_of_files << "#---------------" << "\n"
35
+ end
36
+
37
+ def player_file_exists?
38
+ File.exist?(path + "/player.rb")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ module ScoreboardRubywarrior
2
+ class InvalidPlayerDirectory < StandardError
3
+ end
4
+ end
@@ -1,3 +1,4 @@
1
+ require 'pry'
1
2
  # here we patch the level.rb class to add our reporting
2
3
  module RubyWarrior
3
4
  class Level
@@ -31,6 +32,8 @@ module RubyWarrior
31
32
  @profile.abilities = warrior.abilities.keys
32
33
  report[:warrior_name] = @profile.warrior_name
33
34
  report[:level_number] = @number
35
+ report[:source_code] = ::ScoreboardRubywarrior::Concatenator.new(Dir.pwd).concatenate
36
+
34
37
  ::ScoreboardRubywarrior::Reporter.send_level_update(report)
35
38
  end
36
39
  end
@@ -1,3 +1,3 @@
1
1
  module ScoreboardRubywarrior
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -48,8 +48,10 @@ require 'ruby_warrior/abilities/explode'
48
48
  require 'ruby_warrior/abilities/detonate'
49
49
  require 'ruby_warrior/abilities/form'
50
50
 
51
- require 'scoreboard_rubywarrior/reporter.rb'
52
- require 'scoreboard_rubywarrior/monkeys/level.rb'
51
+ require 'scoreboard_rubywarrior/reporter'
52
+ require 'scoreboard_rubywarrior/concatenator'
53
+ require 'scoreboard_rubywarrior/errors'
54
+ require 'scoreboard_rubywarrior/monkeys/level'
53
55
 
54
56
  module ScoreboardRubywarrior
55
57
 
@@ -0,0 +1,5 @@
1
+ class FileOne
2
+ def method_one
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class FileTwo
2
+ def method_two
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ class Player
2
+
3
+ end
@@ -0,0 +1,5 @@
1
+ class FileThree
2
+ def method_three
3
+
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScoreboardRubywarrior::Concatenator do
4
+ let(:path) { File.expand_path('../../../fixtures/temp_ruby/', __FILE__) }
5
+
6
+ it "should return a string representing all the files" do
7
+ content = ScoreboardRubywarrior::Concatenator.new(path).concatenate
8
+ expect(content).to match('def method_two')
9
+ expect(content).to match('class FileOne')
10
+ expect(content).to match('class FileTwo')
11
+ expect(content).to match('class FileThree')
12
+ end
13
+
14
+ context 'path not containing player.rb' do
15
+ let(:path) { File.expand_path('../../../fixtures/', __FILE__) }
16
+
17
+ it "should rbinding.pryaise an error" do
18
+ expect{ScoreboardRubywarrior::Concatenator.new(path).concatenate}.to raise_exception(ScoreboardRubywarrior::InvalidPlayerDirectory)
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoreboard_rubywarrior
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Davey
@@ -145,10 +145,17 @@ files:
145
145
  - Rakefile
146
146
  - bin/scoreboard_rubywarrior
147
147
  - lib/scoreboard_rubywarrior.rb
148
+ - lib/scoreboard_rubywarrior/concatenator.rb
149
+ - lib/scoreboard_rubywarrior/errors.rb
148
150
  - lib/scoreboard_rubywarrior/monkeys/level.rb
149
151
  - lib/scoreboard_rubywarrior/reporter.rb
150
152
  - lib/scoreboard_rubywarrior/version.rb
151
153
  - scoreboard_rubywarrior.gemspec
154
+ - spec/fixtures/temp_ruby/file_one.rb
155
+ - spec/fixtures/temp_ruby/file_two.rb
156
+ - spec/fixtures/temp_ruby/player.rb
157
+ - spec/fixtures/temp_ruby/subdir/file_three.rb
158
+ - spec/lib/scoreboard_rubywarrior/concatenator_spec.rb
152
159
  - spec/lib/scoreboard_rubywarrior/reporter_spec.rb
153
160
  - spec/spec_helper.rb
154
161
  homepage: ''
@@ -176,5 +183,10 @@ signing_key:
176
183
  specification_version: 4
177
184
  summary: Adds the ability for rubywarrior to publish results to a webserver
178
185
  test_files:
186
+ - spec/fixtures/temp_ruby/file_one.rb
187
+ - spec/fixtures/temp_ruby/file_two.rb
188
+ - spec/fixtures/temp_ruby/player.rb
189
+ - spec/fixtures/temp_ruby/subdir/file_three.rb
190
+ - spec/lib/scoreboard_rubywarrior/concatenator_spec.rb
179
191
  - spec/lib/scoreboard_rubywarrior/reporter_spec.rb
180
192
  - spec/spec_helper.rb