codefusion 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGUwNWU4MDE0Y2QwMmJmOTJkODJkN2RhODA0ZmE1NTNkMWZlZjE2Nw==
5
+ data.tar.gz: !binary |-
6
+ ODgxNmRmMzIwMjZlZDZiMDUzM2Q4YWZjODVjYmZlZjY0NWI4Y2ZmNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTE5Zjg5ODVhZmU2ZDUwZTZkOWRjM2M0ZGQwNTg5ZGU5M2Y5YThkM2NjZDFi
10
+ ZTEwMzM3N2MyOGEzMGEzMTNlYjY5NzYxYTY1MTRiMmYyMWM1NDMwMjc2OTEz
11
+ ZjFmNjhmOTY5ZDZiNTExMThjMDRjMmRjOTlhZTEzNWZhZTRiZGU=
12
+ data.tar.gz: !binary |-
13
+ YjU2NzFhN2EyNzExZGI5OTdjNzYzYTAyMGZmNTBmYTNmZjRkYzkxOTk2ZTNh
14
+ ZGRhZDQyMGMxNDU1NTcxM2FmZTkwOWI5YjMyNzBiODdkYTY0MTFkOGM3ZmI5
15
+ YTgwMmM1NmZiNDA4N2VmYTFiY2ZjNzEzMDc4NzQ5NjJmMzEwMmI=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codefusion.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ #CodeFusion
2
+
3
+ CodeFusion allows a user to specify a file to watch. When the text within the target file changes, the CodeFusion gem records the changes and sends them to the CodeFusion web app. The changes can be viewed in real time at http://www.codefusion.io by anyone who navigates to your session's dynamically generated unique url.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'codefusion'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install codefusion
18
+
19
+ ## Usage
20
+ TODO: Write usage instructions here
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/fusion ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'SecureRandom'
3
+
4
+ require File.expand_path(File.join('..', 'lib', 'codefusion'), File.dirname(__FILE__))
5
+
6
+ Application.new(ARGV)
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codefusion/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codefusion"
8
+ spec.version = Codefusion::VERSION
9
+ spec.authors = ["David Stavis, Ben Myhre, Drew West, Aaron Wertman, James Hulley"]
10
+ spec.email = ["drewfwest@gmail.com"]
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
+ spec.summary = %q{Allows teachers to stream copies of their code to many students, live.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ #/*****************Dependencies*********************
17
+ spec.add_development_dependency('rspec')
18
+ spec.add_development_dependency('pry')
19
+
20
+ spec.add_runtime_dependency('listen')
21
+ spec.add_runtime_dependency('json')
22
+ spec.add_runtime_dependency('httparty')
23
+
24
+ #*****************Dependencies*********************/
25
+
26
+ spec.files = `git ls-files`.split($/)
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.3"
32
+ spec.add_development_dependency "rake"
33
+ end
data/lib/codefusion.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'listen'
2
+ require 'rubygems'
3
+ require 'httparty'
4
+ require 'json'
5
+
6
+ require 'codefusion/classroom'
7
+ require 'codefusion/firebase'
8
+ require 'codefusion/listener'
9
+ require 'codefusion/view'
10
+ require 'codefusion/watch_file'
11
+
12
+ class Application
13
+ attr_reader :args, :view, :classroom, :listener
14
+
15
+ def initialize(args = [])
16
+ @args = args
17
+ @view = View.new
18
+ check_args
19
+ end
20
+
21
+ 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
30
+ end
31
+
32
+ def run_utilities(command)
33
+ if !!(command =~ /^-h$/ || command =~ /^-help$/)
34
+ @view.display_help_info
35
+ else
36
+ display_error_message
37
+ end
38
+ end
39
+
40
+ def run_program
41
+ @classroom = Classroom.new( WatchFile.new(get_file_name) )
42
+ @listener = Listener.new
43
+ @listener.start( @classroom, @view )
44
+ end
45
+
46
+ def display_error_message
47
+ @view.display_message("ERROR: invalid arguments, for help information type '$ fusion -help' or '$ fusion -h'")
48
+ end
49
+
50
+ def get_file_name
51
+ !!(@args[0] =~/^\//) ? @args[0].slice!(0) : @args[0]
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ require 'codefusion/firebase'
2
+ class Classroom
3
+ attr_reader :code, :file
4
+
5
+ include Firebase
6
+
7
+ def initialize(file)
8
+ @code = generate_classroom_code
9
+ @file = file
10
+ end
11
+
12
+ def self.create(file)
13
+ Classroom.new(file)
14
+ Classroom.save
15
+ end
16
+
17
+ 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)
27
+ else
28
+ Firebase.update(request_body, @uuid)
29
+ end
30
+ end
31
+
32
+ def get_file_name ## reduce
33
+ @file.name
34
+ end
35
+
36
+ def get_dir ##reduce
37
+ Dir.pwd
38
+ end
39
+
40
+ def get_watch_url ##reduce
41
+ generate_watch_url
42
+ end
43
+
44
+ private
45
+
46
+ def generate_classroom_code
47
+ SecureRandom::urlsafe_base64(1)
48
+ end
49
+
50
+ def get_uuid(response)
51
+ response["name"]
52
+ end
53
+
54
+ def generate_watch_url
55
+ "http://www.codefusion.io/classrooms/" + @code
56
+ end
57
+
58
+ end
@@ -0,0 +1,32 @@
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
+
@@ -0,0 +1,16 @@
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?
6
+
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)
10
+ end
11
+
12
+ view.display_intro_message(classroom.get_file_name, classroom.get_watch_url)
13
+ file_listener.start
14
+ sleep
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Codefusion
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ class View
2
+ def display_message(message)
3
+ puts " #{message}"
4
+ end
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"
12
+ end
13
+
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"
20
+ end
21
+
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"
30
+ end
31
+ end
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
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
15
+
16
+ it "responds to a method called 'file' " do
17
+ @room.file.should_not be_nil
18
+ end
19
+
20
+ it "returns a WatchFile object when 'file' method is called" do
21
+ @room.file.should be_a WatchFile
22
+ end
23
+
24
+ context "@room_uuid" do
25
+ xit "has an instance variable room_uuid" do
26
+ expect
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Listener do
4
+ before :each do
5
+ File.new( 'new_gem_test_file.txt', 'w+' )
6
+ @classroom = double(Classroom)
7
+ @classroom.stub(:get_file_name) { 'new_gem_test_file.txt' }
8
+ @classroom.stub(:get_dir) { Dir.pwd }
9
+ @classroom.stub(:update) { puts "file changed" }
10
+ @view = double(View)
11
+ @listener = Listener.new()
12
+ @listener.stub(:sleep) { sleep(3) }
13
+ end
14
+
15
+ after :each do
16
+ File.delete('new_gem_test_file.txt')
17
+ end
18
+
19
+ it "instatiates a new instance" do
20
+ expect( @listener).to_not eq(nil)
21
+ end
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") }
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'codefusion'
5
+
6
+ RSpec.configure do |config|
7
+ end
@@ -0,0 +1,30 @@
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
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codefusion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Stavis, Ben Myhre, Drew West, Aaron Wertman, James Hulley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: listen
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Run the fusion command line executable to start a live coding session
112
+ that can be watched by anyone who has the url printed to the command line.
113
+ email:
114
+ - drewfwest@gmail.com
115
+ executables:
116
+ - fusion
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/fusion
126
+ - codefusion.gemspec
127
+ - lib/codefusion.rb
128
+ - lib/codefusion/classroom.rb
129
+ - lib/codefusion/firebase.rb
130
+ - lib/codefusion/listener.rb
131
+ - lib/codefusion/version.rb
132
+ - lib/codefusion/view.rb
133
+ - lib/codefusion/watch_file.rb
134
+ - spec/application_spec.rb
135
+ - spec/classroom_spec.rb
136
+ - spec/firebase_spec.rb
137
+ - spec/listener_spec.rb
138
+ - spec/spec_helper.rb
139
+ - spec/watch_file_spec.rb
140
+ homepage: ''
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.2.2
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Allows teachers to stream copies of their code to many students, live.
164
+ test_files:
165
+ - spec/application_spec.rb
166
+ - spec/classroom_spec.rb
167
+ - spec/firebase_spec.rb
168
+ - spec/listener_spec.rb
169
+ - spec/spec_helper.rb
170
+ - spec/watch_file_spec.rb