Skip to content

Commit

Permalink
rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Apr 7, 2012
1 parent ce8fb95 commit c57020a
Show file tree
Hide file tree
Showing 65 changed files with 1,330 additions and 854 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -7,5 +7,6 @@ gem 'rb-fsevent', git: 'git://github.com/niw/rb-fsevent.git'
group :test do
gem 'rake'
gem 'rspec'
gem 'guard-rspec'
gem 'mocha'
end
12 changes: 10 additions & 2 deletions Gemfile.lock
Expand Up @@ -9,7 +9,13 @@ GEM
specs:
ansi (1.4.2)
diff-lcs (1.1.3)
hashr (0.0.19)
ffi (1.0.11)
guard (1.0.1)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-rspec (0.7.0)
guard (>= 0.10.0)
hashr (0.0.20)
metaclass (0.0.1)
mocha (0.10.5)
metaclass (~> 0.0.1)
Expand All @@ -19,15 +25,17 @@ GEM
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.0)
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
thor (0.14.6)

PLATFORMS
ruby

DEPENDENCIES
ansi
guard-rspec
hashr
mocha
rake
Expand Down
5 changes: 5 additions & 0 deletions Guardfile
@@ -0,0 +1,5 @@
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/space/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
@@ -1,13 +1,8 @@
module Enumerable
def map_with_index(&block)
result = []
each_with_index { |element, ix| result << yield(element, ix) }
result
end

def map_slice(num, &block)
result = []
each_slice(num) { |element| result << yield(element) }
result
end
end unless method_defined?(:map_slice)
end

3 changes: 1 addition & 2 deletions lib/core_ext/string.rb → lib/core_ext/string/wrap.rb
@@ -1,7 +1,6 @@
class String
def wrap(width)
gsub(/(.{1,#{width}})( +|$\n?)|(.{1,#{width}})/, "\\1\\3\n")
end
end unless method_defined?(:wrap)
end


21 changes: 5 additions & 16 deletions lib/space.rb
@@ -1,26 +1,15 @@
require 'yaml'
require 'hashr'
require 'core_ext/enumerable'

module Space
autoload :Action, 'space/action'
# autoload :Action, 'space/action'
autoload :App, 'space/app'
autoload :Config, 'space/config'
autoload :Events, 'space/events'
autoload :Helpers, 'space/helpers'
autoload :Models, 'space/models'
autoload :Screen, 'space/screen'
autoload :System, 'space/system'
autoload :View, 'space/view'
autoload :Shell, 'space/shell'
autoload :Tmux, 'space/tmux'
autoload :Watch, 'space/watch'

autoload :Bundler, 'space/models/bundler'
autoload :Bundle, 'space/models/bundle'
autoload :Commands, 'space/models/commands'
autoload :Command, 'space/models/command'
autoload :Dependency, 'space/models/dependency'
autoload :Git, 'space/models/git'
autoload :Project, 'space/models/project'
autoload :Repos, 'space/models/repos'
autoload :Repo, 'space/models/repo'
autoload :Watcher, 'space/models/watcher'
end

60 changes: 0 additions & 60 deletions lib/space/action.rb

This file was deleted.

27 changes: 0 additions & 27 deletions lib/space/action/builtin.rb

This file was deleted.

44 changes: 0 additions & 44 deletions lib/space/action/development.rb

This file was deleted.

52 changes: 26 additions & 26 deletions lib/space/app.rb
Expand Up @@ -2,50 +2,50 @@

module Space
class App
autoload :Command, 'space/app/command'
autoload :Handler, 'space/app/handler'
autoload :Parser, 'space/app/parser'

include Readline

attr_reader :name, :config, :project, :screen
attr_reader :name, :project, :screen

def initialize(name)
@name = name
@config = Config.load(name)
@project = Project.new(name, config)
@screen = Screen.new(name, config, project, project.repos)
@project = Models::Project.new(name)
@screen = Screen.new(project)

project.add_observer(self)
project.subscribe(screen)
end

def run
render
loop do
line = readline(prompt, true)
break if line.nil?
handle(line) unless line.empty?
end
end

def update
render(prompt: prompt)
refresh
screen.display(:dashboard)
prompt
end

private

def render(options = {})
Watcher.ignore do
screen.clear
print 'gathering data '
Commands.preload
screen.render(options)
def refresh
screen.display(:progress)
Shell::Watcher.ignore do
project.refresh
end
end

def handle(line)
Action.run(project, line)
render
def prompt
loop do
line = readline(screen.prompt, true)
break if line.nil?
handle(line) unless line.empty?
end
end

def prompt
"#{project.repos.scoped? ? project.repos.scope.map { |r| r.name }.join(', ') : name} > "
def handle(line)
screen.display(:progress)
Handler.new(project).run(line)
screen.display(:dashboard)
end
end
end

48 changes: 48 additions & 0 deletions lib/space/app/command.rb
@@ -0,0 +1,48 @@
module Space
class App
class Command
autoload :Execute, 'space/app/command/builtin'
autoload :Refresh, 'space/app/command/builtin'
autoload :Scope, 'space/app/command/builtin'
autoload :Unscope, 'space/app/command/builtin'

autoload :Local, 'space/app/command/development'
autoload :Remote, 'space/app/command/development'

attr_reader :project, :scope, :args

def initialize(project, scope, *args)
@project = project
@scope = scope
@args = args
end

# ::Bundler.with_clean_env do
# end

def run
raise 'not implemented'
end

private

def repos
@repos ||= project.repos.select_by_names(scope)
end

def in_scope
repos.each { |repo| yield repo }
end

def system(cmd)
puts cmd
super
end

def confirm
puts "\n--- hit any key to continue ---\n"
STDIN.getc
end
end
end
end

0 comments on commit c57020a

Please sign in to comment.