codefusion 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/LICENSE.txt +1 -1
- data/bin/fusion +1 -1
- data/codefusion.gemspec +1 -1
- data/lib/codefusion.rb +42 -31
- data/lib/codefusion/classroom.rb +36 -35
- data/lib/codefusion/dir_parser.rb +31 -0
- data/lib/codefusion/file_parser.rb +26 -0
- data/lib/codefusion/firebase_command.rb +39 -0
- data/lib/codefusion/firebase_create_command.rb +9 -0
- data/lib/codefusion/firebase_update_command.rb +13 -0
- data/lib/codefusion/listener.rb +48 -11
- data/lib/codefusion/version.rb +2 -2
- data/lib/codefusion/view.rb +75 -22
- data/spec/classroom_spec.rb +20 -20
- data/spec/codefusion_spec.rb +38 -0
- data/spec/firebase_command_spec.rb +18 -0
- data/spec/listener_spec.rb +7 -7
- metadata +12 -11
- data/lib/codefusion/firebase.rb +0 -32
- data/lib/codefusion/watch_file.rb +0 -20
- data/spec/application_spec.rb +0 -27
- data/spec/firebase_spec.rb +0 -20
- data/spec/watch_file_spec.rb +0 -30
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWU2Nzk2NjI1ZTJjZTc5NmIxZTEzMjU3Y2U5ZTkyMDllODkzMjRjNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Zjc2YTNiZGExMThjNDQ3N2YyY2NkM2E0MmJiOWQ4ZGVkMTEzOGJhOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjIyNWVhNmQ3ZDE0ZjczOGEwMDJkM2M5ZmQ2ODk3NjVhM2Y4NjJmOGYwNTZl
|
10
|
+
NTFlODc0ZWI5YzhmMTE0ZTE5ZTY4ZTdiZGVjYWVhNGE2NWU3MDk2MDA1NDk2
|
11
|
+
ZTIxOGExZGQ3ODM5ZGRjNGMzMjM0ZDUwM2MyNDI0ZDBlMGM4YjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjZhOTZkZjM4Mjg3ZDMyNTM1ZWI1NDhmZjJiMTVlOTk0MTYxZGQwMjIxYzVk
|
14
|
+
NGRkNTI0YzNmOWQzNDBkYzY2ZDAwZjIwMTgxOGZlNGY2M2Q3ZDcxOGIxOTFk
|
15
|
+
ZWM2NDllNDUwYjExNzdmNjk5MzhkOTIwY2E2Yzg5YjlkMjQ5ZGM=
|
data/LICENSE.txt
CHANGED
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/fusion
CHANGED
data/codefusion.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'codefusion/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "codefusion"
|
8
8
|
spec.version = Codefusion::VERSION
|
9
|
-
spec.authors = ["
|
9
|
+
spec.authors = ["Aaron Wertman, Ben Myhre, David Stavis, Drew West, James Hulley"]
|
10
10
|
spec.email = ["drewfwest@gmail.com"]
|
11
11
|
spec.description = %q{Run the fusion command line executable to start a live coding session that can be watched by anyone who has the url printed to the command line.}
|
12
12
|
spec.summary = %q{Allows teachers to stream copies of their code to many students, live.}
|
data/lib/codefusion.rb
CHANGED
@@ -1,53 +1,64 @@
|
|
1
|
-
require 'listen'
|
2
1
|
require 'rubygems'
|
3
|
-
require 'httparty'
|
4
2
|
require 'json'
|
3
|
+
require 'listen'
|
4
|
+
require 'httparty'
|
5
5
|
|
6
6
|
require 'codefusion/classroom'
|
7
|
-
require 'codefusion/
|
7
|
+
require 'codefusion/dir_parser'
|
8
|
+
require 'codefusion/file_parser'
|
9
|
+
require 'codefusion/firebase_command'
|
10
|
+
require 'codefusion/firebase_create_command'
|
11
|
+
require 'codefusion/firebase_update_command'
|
8
12
|
require 'codefusion/listener'
|
9
13
|
require 'codefusion/view'
|
10
|
-
require 'codefusion/watch_file'
|
11
|
-
|
12
|
-
class Application
|
13
|
-
attr_reader :args, :view, :classroom, :listener
|
14
14
|
|
15
|
+
class CodefusionApp
|
15
16
|
def initialize(args = [])
|
16
17
|
@args = args
|
17
|
-
@
|
18
|
-
|
18
|
+
@file = ""
|
19
|
+
interpret_args
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
|
-
def
|
23
|
-
|
24
|
-
run_utilities(@args[0])
|
25
|
-
elsif !!(@args[0] =~ /^\w/)
|
26
|
-
run_program
|
27
|
-
else
|
28
|
-
display_error_message
|
29
|
-
end
|
23
|
+
def interpret_args
|
24
|
+
(path_given? and valid_path?) ? execute_command : provide_help
|
30
25
|
end
|
31
26
|
|
32
|
-
def
|
33
|
-
|
34
|
-
@view.display_help_info
|
35
|
-
else
|
36
|
-
display_error_message
|
37
|
-
end
|
27
|
+
def path
|
28
|
+
@args[0]
|
38
29
|
end
|
39
30
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
def path_given?
|
32
|
+
path != nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid_path?
|
36
|
+
path_is_dir? || path_is_file?
|
44
37
|
end
|
45
38
|
|
46
|
-
def
|
47
|
-
|
39
|
+
def path_is_file?
|
40
|
+
File.file?(path)
|
48
41
|
end
|
49
42
|
|
50
|
-
def
|
51
|
-
|
43
|
+
def path_is_dir?
|
44
|
+
File.directory?(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def provide_help
|
48
|
+
View.help_info
|
49
|
+
end
|
50
|
+
|
51
|
+
def execute_command
|
52
|
+
set_path
|
53
|
+
run_program
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_path
|
57
|
+
@path = Dir.pwd
|
58
|
+
path_is_dir? ? Dir.chdir(path) : @file = path
|
59
|
+
end
|
60
|
+
|
61
|
+
def run_program
|
62
|
+
Listener.new(Classroom.new(@path, @file) ).start
|
52
63
|
end
|
53
64
|
end
|
data/lib/codefusion/classroom.rb
CHANGED
@@ -1,58 +1,59 @@
|
|
1
|
-
require 'codefusion/
|
2
|
-
|
3
|
-
attr_reader :code, :file
|
4
|
-
|
5
|
-
include Firebase
|
1
|
+
require 'codefusion/firebase_create_command'
|
2
|
+
require 'codefusion/firebase_update_command'
|
6
3
|
|
7
|
-
|
8
|
-
|
4
|
+
class Classroom
|
5
|
+
attr_reader :path, :parent_dir, :file
|
6
|
+
include FirebaseUpdateCommand
|
7
|
+
include FirebaseCreateCommand
|
8
|
+
|
9
|
+
def initialize(path, file)
|
10
|
+
@path = path
|
11
|
+
@dir = path.split('/').last
|
12
|
+
@parent_dir = File.dirname(path)
|
13
|
+
@code = new_code
|
9
14
|
@file = file
|
10
|
-
|
11
|
-
|
12
|
-
def self.create(file)
|
13
|
-
Classroom.new(file)
|
14
|
-
Classroom.save
|
15
|
+
update
|
15
16
|
end
|
16
17
|
|
17
18
|
def update
|
18
|
-
@
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def save
|
23
|
-
request_body = [@code, @file.name, @file.content] #would love to extract this into some other model
|
24
|
-
unless @uuid
|
25
|
-
response = Firebase.create(request_body)
|
26
|
-
@uuid = get_uuid(response)
|
19
|
+
request = [@code, make_hash]
|
20
|
+
if @uuid
|
21
|
+
FirebaseUpdateCommand.update(request, @uuid)
|
27
22
|
else
|
28
|
-
|
23
|
+
@uuid = set_uuid(FirebaseCreateCommand.create(request))
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
32
|
-
def
|
33
|
-
|
27
|
+
def url
|
28
|
+
generate_url
|
34
29
|
end
|
35
30
|
|
36
|
-
|
37
|
-
|
31
|
+
private
|
32
|
+
def generate_url
|
33
|
+
"http://codefusion.io/classrooms/#{@code}"
|
38
34
|
end
|
39
35
|
|
40
|
-
def
|
41
|
-
|
36
|
+
def new_code
|
37
|
+
current_codes.include?(generate_code) ? new_code : generate_code
|
42
38
|
end
|
43
39
|
|
44
|
-
|
40
|
+
def generate_code
|
41
|
+
SecureRandom::hex(3)
|
42
|
+
end
|
45
43
|
|
46
|
-
def
|
47
|
-
|
44
|
+
def current_codes
|
45
|
+
FirebaseCommand.classroom_codes
|
48
46
|
end
|
49
47
|
|
50
|
-
def
|
48
|
+
def set_uuid(response)
|
51
49
|
response["name"]
|
52
50
|
end
|
53
51
|
|
54
|
-
def
|
55
|
-
"
|
52
|
+
def make_hash
|
53
|
+
if @file == ""
|
54
|
+
DirParser.make_hash(@dir, @parent_dir)
|
55
|
+
else
|
56
|
+
FileParser.make_hash(@path, @file, @parent_dir)
|
57
|
+
end
|
56
58
|
end
|
57
|
-
|
58
59
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module DirParser
|
2
|
+
def self.make_hash(dir, parent_dir)
|
3
|
+
full_path = File.join(parent_dir, dir)
|
4
|
+
children = Dir.entries(full_path).partition do |child|
|
5
|
+
File.directory?( File.join(full_path, child) )
|
6
|
+
end
|
7
|
+
{ folder_name: dir,
|
8
|
+
files: DirParser.return_files( children[1], full_path, parent_dir ),
|
9
|
+
folders: DirParser.return_folders( children[0], dir, parent_dir )
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def self.return_files(children, full_path, parent_dir)
|
15
|
+
children.map do |file|
|
16
|
+
begin
|
17
|
+
if File.read( File.join(full_path, file)).to_json
|
18
|
+
{ file_name: FileParser.shortened_path( File.join(full_path, file) , parent_dir ),
|
19
|
+
file_content: File.read( File.join(full_path, file) )
|
20
|
+
}
|
21
|
+
end
|
22
|
+
rescue Exception => e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.return_folders(children, dir, parent_dir)
|
28
|
+
children.reject! { |child| child =~ /\./ }
|
29
|
+
children.map { |folder| DirParser.make_hash( File.join(dir, folder), parent_dir ) }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module FileParser
|
2
|
+
def self.make_hash(path, file, parent_dir)
|
3
|
+
{ folder_name: "",
|
4
|
+
files: FileParser.return_file(path, file, parent_dir) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.shortened_path(path, parent_dir)
|
8
|
+
path.slice!(parent_dir)
|
9
|
+
path[1..-1]
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def self.return_file(path, file, parent_dir)
|
14
|
+
begin
|
15
|
+
if File.read( File.join(path, file) ).to_json
|
16
|
+
[ { file_name: FileParser.shortened_path( File.join(path, file), parent_dir ),
|
17
|
+
file_content: File.read( File.join(path, file) )
|
18
|
+
}
|
19
|
+
]
|
20
|
+
end
|
21
|
+
rescue Exception => e
|
22
|
+
View.wrong_filetype_message( File.extname(file) )
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FirebaseCommand
|
2
|
+
include HTTParty
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def uri
|
6
|
+
"https://radiant-fire-3325.firebaseio.com/classrooms"
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_config(request)
|
10
|
+
{ body: make_json(request),
|
11
|
+
options: { headers: { "Content-Type" => "application/json"} }
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def classroom_codes
|
16
|
+
parse_classroom_codes( parse_values(response) )
|
17
|
+
end
|
18
|
+
|
19
|
+
def request_url(uuid = "")
|
20
|
+
"#{uri}/#{uuid}.json"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def make_json(request)
|
25
|
+
{ classroom_code: request[0], content: request[1] }.to_json
|
26
|
+
end
|
27
|
+
|
28
|
+
def response
|
29
|
+
HTTParty.get(request_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_values(response)
|
33
|
+
JSON.parse(response.body).values
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_classroom_codes(classrooms)
|
37
|
+
classrooms.map { |classroom| classroom["classroom_code"] }
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'codefusion/firebase_command'
|
2
|
+
module FirebaseUpdateCommand
|
3
|
+
include FirebaseCommand
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def update(request, uuid)
|
7
|
+
if uuid == ""
|
8
|
+
View.error_message
|
9
|
+
else
|
10
|
+
HTTParty.put( FirebaseCommand.request_url(uuid), FirebaseCommand.get_config(request) )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/codefusion/listener.rb
CHANGED
@@ -1,16 +1,53 @@
|
|
1
1
|
class Listener
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def initialize(classroom)
|
3
|
+
@classroom = classroom
|
4
|
+
end
|
5
|
+
|
6
|
+
def start
|
7
|
+
begin
|
8
|
+
View.listen_message(@classroom.path, url)
|
9
|
+
set_listener.start
|
10
|
+
sleep
|
11
|
+
rescue Exception => e
|
12
|
+
View.exit_message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def set_listener
|
18
|
+
Listen.to(@classroom.path, only: this_file) do |modified, added, removed|
|
19
|
+
relative_path = get_relative_path(modified, added, removed)
|
20
|
+
send_message(applicable_message(modified, added, removed), relative_path)
|
21
|
+
@classroom.update
|
22
|
+
end
|
23
|
+
end
|
6
24
|
|
7
|
-
|
8
|
-
|
9
|
-
|
25
|
+
def applicable_message(modified, added, removed)
|
26
|
+
if modified.any?
|
27
|
+
:modified_message
|
28
|
+
elsif added.any? && removed.any?
|
29
|
+
:name_changed_message
|
30
|
+
elsif added.any?
|
31
|
+
:added_message
|
32
|
+
else removed.any?
|
33
|
+
:removed_message
|
10
34
|
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def this_file
|
38
|
+
@classroom.file ? Regexp.new(@classroom.file) : /./
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_relative_path(modified, added, removed)
|
42
|
+
full_path = [modified, added, removed].select { |effect| effect.any? }.flatten.first
|
43
|
+
FileParser.shortened_path(full_path, @classroom.parent_dir)
|
44
|
+
end
|
45
|
+
|
46
|
+
def url
|
47
|
+
@classroom.url
|
48
|
+
end
|
11
49
|
|
12
|
-
|
13
|
-
|
14
|
-
sleep
|
50
|
+
def send_message(message, path)
|
51
|
+
View.send(message, path, url)
|
15
52
|
end
|
16
|
-
end
|
53
|
+
end
|
data/lib/codefusion/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Codefusion
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
data/lib/codefusion/view.rb
CHANGED
@@ -1,31 +1,84 @@
|
|
1
|
-
|
2
|
-
def display_message(message)
|
1
|
+
module View
|
2
|
+
def self.display_message(message)
|
3
3
|
puts " #{message}"
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
7
|
-
puts
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
def self.listen_message(file_name, url)
|
7
|
+
puts <<-EOM
|
8
|
+
|
9
|
+
listening to: #{file_name}
|
10
|
+
view at: #{url}
|
11
|
+
stop: 'ctrl + c'
|
12
|
+
EOM
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.modified_message(file_name, url)
|
16
|
+
puts <<-EOM
|
17
|
+
|
18
|
+
update: #{file_name}
|
19
|
+
view: #{url}
|
20
|
+
stop: 'ctrl + c'
|
21
|
+
EOM
|
12
22
|
end
|
13
23
|
|
14
|
-
def
|
15
|
-
puts
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
def self.name_changed_message(file_name, url)
|
25
|
+
puts <<-EOM
|
26
|
+
|
27
|
+
name change: #{file_name}
|
28
|
+
view: #{url}
|
29
|
+
stop: 'ctrl + c'
|
30
|
+
EOM
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.added_message(file_name, url)
|
34
|
+
puts <<-EOM
|
35
|
+
|
36
|
+
new: #{file_name}
|
37
|
+
view: #{url}
|
38
|
+
stop: 'ctrl + c'
|
39
|
+
EOM
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.removed_message(file_name, url)
|
43
|
+
puts <<-EOM
|
44
|
+
|
45
|
+
deleted: #{file_name}
|
46
|
+
view: #{url}
|
47
|
+
stop: 'ctrl + c'
|
48
|
+
EOM
|
20
49
|
end
|
21
50
|
|
22
|
-
def
|
23
|
-
puts
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
51
|
+
def self.help_info
|
52
|
+
puts <<-EOM
|
53
|
+
|
54
|
+
To use codefusion:
|
55
|
+
1. type 'fusion <path_name>'
|
56
|
+
2. ensure path is valid
|
57
|
+
3. if path is valid, codefusion will start watching the file or directory for updates
|
58
|
+
and provide a URL to your classroom
|
59
|
+
4. to close, press 'ctrl + c'
|
60
|
+
EOM
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.error_message
|
64
|
+
puts <<-EOM
|
65
|
+
Something went wrong with the connection to your file.
|
66
|
+
Please exit codefusion and restart your session.
|
67
|
+
EOM
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.wrong_filetype_message(file)
|
71
|
+
puts <<-EOM
|
72
|
+
|
73
|
+
The '#{file}' file type cannot be watched.
|
74
|
+
EOM
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.exit_message
|
78
|
+
puts <<-EOM
|
79
|
+
|
80
|
+
Thanks for using codefusion!
|
81
|
+
|
82
|
+
EOM
|
30
83
|
end
|
31
84
|
end
|
data/spec/classroom_spec.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Classroom do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@room.code.should_not be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
xit "responds to a method called 'root_dir_path' " do
|
13
|
-
@room.root_dir_path.should_not be_nil
|
14
|
-
end
|
4
|
+
context "Testing initialize without update" do
|
5
|
+
before(:each) do
|
6
|
+
Classroom.any_instance.stub(:update){"hi"}
|
7
|
+
@this_class=Classroom.new('/Users' ,'README.md')
|
8
|
+
end
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
it "generates a new code" do
|
11
|
+
expect(:code).to_not eq(nil)
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
14
|
+
it "initializes with the root directory being assiged to dir" do
|
15
|
+
expect(@this_class.instance_variable_get(:@dir)).to eq("Users")
|
16
|
+
end
|
22
17
|
end
|
23
18
|
|
24
|
-
context "
|
25
|
-
|
26
|
-
|
19
|
+
context "Testing initialize update if uuid" do
|
20
|
+
before(:each) do
|
21
|
+
make_hash.any_instance.stub(:update){"hi"}
|
22
|
+
FirebaseCreateCommand.any_instance.stub(:create){{"name"=>"create"}}
|
23
|
+
FirebaseUpdateCommand.any_instance.stub(:update){{"name"=>"update"}}
|
24
|
+
@this_class=Classroom.new('/Users' ,'README.md')
|
25
|
+
@this_class.extend(FirebaseUpdateCommand)
|
26
|
+
@this_class.extend(FirebaseUpdateCommand)
|
27
|
+
@this_class.stub(:make_hash){{:this=> "hash"}}
|
27
28
|
end
|
28
29
|
end
|
29
|
-
|
30
30
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe CodefusionApp do
|
3
|
+
before :each do
|
4
|
+
File.new('test.txt', 'w+')
|
5
|
+
args=["test.txt"]
|
6
|
+
@codefusion=double( CodefusionApp, args: "test.txt", view: double(View), classroom: double(Classroom), listener: double(Listener) )
|
7
|
+
@codefusion.stub(:interpret_args) { 'this ran' }
|
8
|
+
@codefusion.stub(:provide_help) { 'this is an error' }
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
File.delete('test.txt')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "instatiates a new instance" do
|
16
|
+
expect(@codefusion).to_not eq(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "shows that interpret_args runs" do
|
20
|
+
expect(:interpret_args).to_not eq(nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "instatiates with args" do
|
24
|
+
expect(@codefusion.args).to eq("test.txt")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "instatiates with a view" do
|
28
|
+
expect(@codefusion.view).to_not eq(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "creates a new classroom if passed valid arguments" do
|
32
|
+
expect(@codefusion.classroom).to_not eq(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates a new listener if passed valid arguments" do
|
36
|
+
expect(@codefusion.listener).to_not eq(nil)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FirebaseCreateCommand do
|
4
|
+
context "#create" do
|
5
|
+
it "responds" do
|
6
|
+
expect(FirebaseCreateCommand.create(['TEST', 'test_room', 'test_text'])).to_not be_nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
describe FirebaseUpdateCommand do
|
13
|
+
context "#update" do
|
14
|
+
it "responds" do
|
15
|
+
expect(FirebaseUpdateCommand.update(['TEST', 'test_room', 'test_text'], 'test')).to_not be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/listener_spec.rb
CHANGED
@@ -2,26 +2,26 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Listener do
|
4
4
|
before :each do
|
5
|
-
File.new( '
|
5
|
+
File.new( 'fun.txt', 'w+' )
|
6
6
|
@classroom = double(Classroom)
|
7
|
-
@classroom.stub(:get_file_name) { '
|
7
|
+
@classroom.stub(:get_file_name) { 'fun.txt' }
|
8
8
|
@classroom.stub(:get_dir) { Dir.pwd }
|
9
9
|
@classroom.stub(:update) { puts "file changed" }
|
10
10
|
@view = double(View)
|
11
|
-
@listener = Listener.new()
|
11
|
+
@listener = Listener.new(@classroom)
|
12
12
|
@listener.stub(:sleep) { sleep(3) }
|
13
13
|
end
|
14
14
|
|
15
15
|
after :each do
|
16
|
-
File.delete('
|
16
|
+
File.delete('fun.txt')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "instatiates a new instance" do
|
20
20
|
expect( @listener).to_not eq(nil)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
@listener.start
|
25
|
-
File.open('
|
23
|
+
it "calls update on the classroom on file change" do
|
24
|
+
@listener.start
|
25
|
+
File.open('fun.txt', 'w+') { |f| f.write("test text") }
|
26
26
|
end
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codefusion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Aaron Wertman, Ben Myhre, David Stavis, Drew West, James Hulley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -126,17 +126,19 @@ files:
|
|
126
126
|
- codefusion.gemspec
|
127
127
|
- lib/codefusion.rb
|
128
128
|
- lib/codefusion/classroom.rb
|
129
|
-
- lib/codefusion/
|
129
|
+
- lib/codefusion/dir_parser.rb
|
130
|
+
- lib/codefusion/file_parser.rb
|
131
|
+
- lib/codefusion/firebase_command.rb
|
132
|
+
- lib/codefusion/firebase_create_command.rb
|
133
|
+
- lib/codefusion/firebase_update_command.rb
|
130
134
|
- lib/codefusion/listener.rb
|
131
135
|
- lib/codefusion/version.rb
|
132
136
|
- lib/codefusion/view.rb
|
133
|
-
- lib/codefusion/watch_file.rb
|
134
|
-
- spec/application_spec.rb
|
135
137
|
- spec/classroom_spec.rb
|
136
|
-
- spec/
|
138
|
+
- spec/codefusion_spec.rb
|
139
|
+
- spec/firebase_command_spec.rb
|
137
140
|
- spec/listener_spec.rb
|
138
141
|
- spec/spec_helper.rb
|
139
|
-
- spec/watch_file_spec.rb
|
140
142
|
homepage: ''
|
141
143
|
licenses:
|
142
144
|
- MIT
|
@@ -162,9 +164,8 @@ signing_key:
|
|
162
164
|
specification_version: 4
|
163
165
|
summary: Allows teachers to stream copies of their code to many students, live.
|
164
166
|
test_files:
|
165
|
-
- spec/application_spec.rb
|
166
167
|
- spec/classroom_spec.rb
|
167
|
-
- spec/
|
168
|
+
- spec/codefusion_spec.rb
|
169
|
+
- spec/firebase_command_spec.rb
|
168
170
|
- spec/listener_spec.rb
|
169
171
|
- spec/spec_helper.rb
|
170
|
-
- spec/watch_file_spec.rb
|
data/lib/codefusion/firebase.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Firebase
|
2
|
-
include HTTParty
|
3
|
-
|
4
|
-
extend self
|
5
|
-
|
6
|
-
# ENV[:firebase_uri]
|
7
|
-
@firebase_uri = "https://radiant-fire-3325.firebaseio.com/classrooms"
|
8
|
-
|
9
|
-
def create(body)
|
10
|
-
HTTParty.post(make_request_url, get_config(body))
|
11
|
-
end
|
12
|
-
|
13
|
-
def update(body, uuid)
|
14
|
-
HTTParty.put(make_request_url(uuid), get_config(body))
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def make_request_url(uuid = "")
|
20
|
-
@firebase_uri + '/' + uuid + '.json'
|
21
|
-
end
|
22
|
-
|
23
|
-
def make_json(body)
|
24
|
-
return {classroom_code: body[0], file_name: body[1], file_content: body[2]}.to_json
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_config(body)
|
28
|
-
return {:body => make_json(body), :options => { :headers => { "Content-Type" => "application/json"}}}
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class WatchFile
|
2
|
-
attr_reader :name, :full_path, :content
|
3
|
-
|
4
|
-
def initialize(filename) #refactor: use actual Ruby file objects so that fusion command supports path-completion in ARGV
|
5
|
-
@name = filename
|
6
|
-
@full_path = Dir.pwd + "/" + @name
|
7
|
-
@content = read_file
|
8
|
-
end
|
9
|
-
|
10
|
-
def update
|
11
|
-
@content = read_file
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def read_file
|
17
|
-
return File.read(@full_path)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/application_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Application do
|
4
|
-
before :each do
|
5
|
-
@application = Application.new(["fun"])
|
6
|
-
end
|
7
|
-
|
8
|
-
it "instatiates a new instance" do
|
9
|
-
expect( @application ).to_not eq(nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "instatiates with args" do
|
13
|
-
expect( @application.args ).to eq(["fun"])
|
14
|
-
end
|
15
|
-
|
16
|
-
it "instatiates with a view" do
|
17
|
-
expect( @application.view ).to_not eq(nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "creates a new classroom if passed valid arguments" do
|
21
|
-
expect( @application.classroom ).to_not eq(nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "creates a new listener if passed valid arguments" do
|
25
|
-
expect( @application.listener ).to_not eq(nil)
|
26
|
-
end
|
27
|
-
end
|
data/spec/firebase_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Firebase do
|
4
|
-
it "is a module" do
|
5
|
-
expect(Firebase).to be_a Module
|
6
|
-
end
|
7
|
-
|
8
|
-
context "#create" do
|
9
|
-
it "responds" do
|
10
|
-
expect(Firebase.create).to_not be_nil
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "#update" do
|
15
|
-
it "responds" do
|
16
|
-
expect(Firebase.update).to_not be_nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/watch_file_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WatchFile do
|
4
|
-
before(:each) do
|
5
|
-
@watch_file = WatchFile.new('README.md')
|
6
|
-
end
|
7
|
-
|
8
|
-
context "#name" do
|
9
|
-
it "responds to a method called 'name' " do
|
10
|
-
@watch_file.name.should_not be_nil
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "#full_path" do
|
15
|
-
it "responds to a method called 'full_path' " do
|
16
|
-
@watch_file.full_path.should_not be_nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "#content" do
|
21
|
-
it "responds to a method called 'content' " do
|
22
|
-
@watch_file.content.should_not be_nil
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns a String object when 'content' is called" do
|
26
|
-
@watch_file.content.should be_a String
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|