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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ gem 'rb-fsevent', git: 'git://github.com/niw/rb-fsevent.git'
group :test do group :test do
gem 'rake' gem 'rake'
gem 'rspec' gem 'rspec'
gem 'guard-rspec'
gem 'mocha' gem 'mocha'
end end
12 changes: 10 additions & 2 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ GEM
specs: specs:
ansi (1.4.2) ansi (1.4.2)
diff-lcs (1.1.3) 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) metaclass (0.0.1)
mocha (0.10.5) mocha (0.10.5)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
Expand All @@ -19,15 +25,17 @@ GEM
rspec-expectations (~> 2.9.0) rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0) rspec-mocks (~> 2.9.0)
rspec-core (2.9.0) rspec-core (2.9.0)
rspec-expectations (2.9.0) rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3) diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0) rspec-mocks (2.9.0)
thor (0.14.6)


PLATFORMS PLATFORMS
ruby ruby


DEPENDENCIES DEPENDENCIES
ansi ansi
guard-rspec
hashr hashr
mocha mocha
rake rake
Expand Down
5 changes: 5 additions & 0 deletions Guardfile
Original file line number Original file line Diff line number Diff line change
@@ -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
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,8 @@
module Enumerable module Enumerable
def map_with_index(&block)
result = []
each_with_index { |element, ix| result << yield(element, ix) }
result
end

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

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



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


module Space module Space
autoload :Action, 'space/action' # autoload :Action, 'space/action'
autoload :App, 'space/app' autoload :App, 'space/app'
autoload :Config, 'space/config' autoload :Config, 'space/config'
autoload :Events, 'space/events'
autoload :Helpers, 'space/helpers' autoload :Helpers, 'space/helpers'
autoload :Models, 'space/models'
autoload :Screen, 'space/screen' autoload :Screen, 'space/screen'
autoload :System, 'space/system' autoload :Shell, 'space/shell'
autoload :View, 'space/view'
autoload :Tmux, 'space/tmux' 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 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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@


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

include Readline include Readline


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


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


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


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

def update
render(prompt: prompt)
end end


private private


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


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


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

48 changes: 48 additions & 0 deletions lib/space/app/command.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
Loading

0 comments on commit c57020a

Please sign in to comment.