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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGUwNWU4MDE0Y2QwMmJmOTJkODJkN2RhODA0ZmE1NTNkMWZlZjE2Nw==
4
+ ZWU2Nzk2NjI1ZTJjZTc5NmIxZTEzMjU3Y2U5ZTkyMDllODkzMjRjNg==
5
5
  data.tar.gz: !binary |-
6
- ODgxNmRmMzIwMjZlZDZiMDUzM2Q4YWZjODVjYmZlZjY0NWI4Y2ZmNA==
6
+ Zjc2YTNiZGExMThjNDQ3N2YyY2NkM2E0MmJiOWQ4ZGVkMTEzOGJhOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTE5Zjg5ODVhZmU2ZDUwZTZkOWRjM2M0ZGQwNTg5ZGU5M2Y5YThkM2NjZDFi
10
- ZTEwMzM3N2MyOGEzMGEzMTNlYjY5NzYxYTY1MTRiMmYyMWM1NDMwMjc2OTEz
11
- ZjFmNjhmOTY5ZDZiNTExMThjMDRjMmRjOTlhZTEzNWZhZTRiZGU=
9
+ YjIyNWVhNmQ3ZDE0ZjczOGEwMDJkM2M5ZmQ2ODk3NjVhM2Y4NjJmOGYwNTZl
10
+ NTFlODc0ZWI5YzhmMTE0ZTE5ZTY4ZTdiZGVjYWVhNGE2NWU3MDk2MDA1NDk2
11
+ ZTIxOGExZGQ3ODM5ZGRjNGMzMjM0ZDUwM2MyNDI0ZDBlMGM4YjE=
12
12
  data.tar.gz: !binary |-
13
- YjU2NzFhN2EyNzExZGI5OTdjNzYzYTAyMGZmNTBmYTNmZjRkYzkxOTk2ZTNh
14
- ZGRhZDQyMGMxNDU1NTcxM2FmZTkwOWI5YjMyNzBiODdkYTY0MTFkOGM3ZmI5
15
- YTgwMmM1NmZiNDA4N2VmYTFiY2ZjNzEzMDc4NzQ5NjJmMzEwMmI=
13
+ NjZhOTZkZjM4Mjg3ZDMyNTM1ZWI1NDhmZjJiMTVlOTk0MTYxZGQwMjIxYzVk
14
+ NGRkNTI0YzNmOWQzNDBkYzY2ZDAwZjIwMTgxOGZlNGY2M2Q3ZDcxOGIxOTFk
15
+ ZWM2NDllNDUwYjExNzdmNjk5MzhkOTIwY2E2Yzg5YjlkMjQ5ZGM=
@@ -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
@@ -3,4 +3,4 @@ require 'SecureRandom'
3
3
 
4
4
  require File.expand_path(File.join('..', 'lib', 'codefusion'), File.dirname(__FILE__))
5
5
 
6
- Application.new(ARGV)
6
+ CodefusionApp.new(ARGV)
@@ -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 = ["David Stavis, Ben Myhre, Drew West, Aaron Wertman, James Hulley"]
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.}
@@ -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/firebase'
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
- @view = View.new
18
- check_args
18
+ @file = ""
19
+ interpret_args
19
20
  end
20
21
 
21
22
  private
22
- def check_args
23
- if !!(@args[0] =~ /^-/)
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 run_utilities(command)
33
- if !!(command =~ /^-h$/ || command =~ /^-help$/)
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 run_program
41
- @classroom = Classroom.new( WatchFile.new(get_file_name) )
42
- @listener = Listener.new
43
- @listener.start( @classroom, @view )
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 display_error_message
47
- @view.display_message("ERROR: invalid arguments, for help information type '$ fusion -help' or '$ fusion -h'")
39
+ def path_is_file?
40
+ File.file?(path)
48
41
  end
49
42
 
50
- def get_file_name
51
- !!(@args[0] =~/^\//) ? @args[0].slice!(0) : @args[0]
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
@@ -1,58 +1,59 @@
1
- require 'codefusion/firebase'
2
- class Classroom
3
- attr_reader :code, :file
4
-
5
- include Firebase
1
+ require 'codefusion/firebase_create_command'
2
+ require 'codefusion/firebase_update_command'
6
3
 
7
- def initialize(file)
8
- @code = generate_classroom_code
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
- end
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
- @file.update
19
- save
20
- end
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
- Firebase.update(request_body, @uuid)
23
+ @uuid = set_uuid(FirebaseCreateCommand.create(request))
29
24
  end
30
25
  end
31
26
 
32
- def get_file_name ## reduce
33
- @file.name
27
+ def url
28
+ generate_url
34
29
  end
35
30
 
36
- def get_dir ##reduce
37
- Dir.pwd
31
+ private
32
+ def generate_url
33
+ "http://codefusion.io/classrooms/#{@code}"
38
34
  end
39
35
 
40
- def get_watch_url ##reduce
41
- generate_watch_url
36
+ def new_code
37
+ current_codes.include?(generate_code) ? new_code : generate_code
42
38
  end
43
39
 
44
- private
40
+ def generate_code
41
+ SecureRandom::hex(3)
42
+ end
45
43
 
46
- def generate_classroom_code
47
- SecureRandom::urlsafe_base64(1)
44
+ def current_codes
45
+ FirebaseCommand.classroom_codes
48
46
  end
49
47
 
50
- def get_uuid(response)
48
+ def set_uuid(response)
51
49
  response["name"]
52
50
  end
53
51
 
54
- def generate_watch_url
55
- "http://www.codefusion.io/classrooms/" + @code
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,9 @@
1
+ require 'codefusion/firebase_command'
2
+ module FirebaseCreateCommand
3
+ include FirebaseCommand
4
+ extend self
5
+
6
+ def create(request)
7
+ HTTParty.post( FirebaseCommand.request_url, FirebaseCommand.get_config(request) )
8
+ end
9
+ 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
@@ -1,16 +1,53 @@
1
1
  class Listener
2
- def start(classroom, view)
3
- file_pattern = Regexp.new(classroom.get_file_name)
4
- file_dir = classroom.get_dir
5
- # TODO check if file is valid?
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
- file_listener = Listen.to(file_dir, only: file_pattern) do |modified, added, removed|
8
- classroom.update
9
- view.display_update_message(classroom.get_file_name, classroom.get_watch_url)
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
- view.display_intro_message(classroom.get_file_name, classroom.get_watch_url)
13
- file_listener.start
14
- sleep
50
+ def send_message(message, path)
51
+ View.send(message, path, url)
15
52
  end
16
- end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Codefusion
2
- VERSION = "0.1.0"
3
- end
2
+ VERSION = "0.2.0"
3
+ end
@@ -1,31 +1,84 @@
1
- class View
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 display_update_message(file_name, url)
7
- puts "\n"
8
- puts " Update detected in #{file_name}"
9
- puts " To see live updates, go to #{url}"
10
- puts " To stop sharing updates, press 'ctrl + c'"
11
- puts "\n"
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 display_intro_message(file_name, url)
15
- puts "\n"
16
- puts " Now listening to changes in #{file_name}"
17
- puts " To see live updates, go to #{url}"
18
- puts " To stop sharing updates, press 'ctrl + c'"
19
- puts "\n"
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 display_help_info
23
- puts "\n"
24
- puts " To use codefusion:"
25
- puts " 1. cd into directory with file you want to watch"
26
- puts " 2. type '$ fusion <file_name>'"
27
- puts " 3. if the file name is valid, fusion will start watching the file for updates and display the URL to go to for updates"
28
- puts " 4. to end the process, press 'ctrl + c'"
29
- puts "\n"
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
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Classroom do
4
- before(:each) do
5
- @room = Classroom.new(WatchFile.new('README.md'))
6
- end
7
-
8
- it "responds to a method called 'code' " do
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
- it "responds to a method called 'file' " do
17
- @room.file.should_not be_nil
18
- end
10
+ it "generates a new code" do
11
+ expect(:code).to_not eq(nil)
12
+ end
19
13
 
20
- it "returns a WatchFile object when 'file' method is called" do
21
- @room.file.should be_a WatchFile
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 "@room_uuid" do
25
- xit "has an instance variable room_uuid" do
26
- expect
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
@@ -2,26 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe Listener do
4
4
  before :each do
5
- File.new( 'new_gem_test_file.txt', 'w+' )
5
+ File.new( 'fun.txt', 'w+' )
6
6
  @classroom = double(Classroom)
7
- @classroom.stub(:get_file_name) { 'new_gem_test_file.txt' }
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('new_gem_test_file.txt')
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
- xit "calls update on the classroom on file change" do
24
- @listener.start(@classroom, @view)
25
- File.open('new_gem_test_file.txt', 'w+') { |f| f.write("test text") }
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - David Stavis, Ben Myhre, Drew West, Aaron Wertman, James Hulley
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-25 00:00:00.000000000 Z
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/firebase.rb
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/firebase_spec.rb
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/firebase_spec.rb
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
@@ -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
@@ -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
@@ -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
@@ -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