space 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/bin/space +6 -0
  2. data/lib/core_ext/string/deansi.rb +7 -0
  3. data/lib/core_ext/string/demodulize.rb +5 -0
  4. data/lib/space.rb +4 -4
  5. data/lib/space/action.rb +43 -0
  6. data/lib/space/action/builtin.rb +43 -0
  7. data/lib/space/action/development.rb +56 -0
  8. data/lib/space/{app → action}/handler.rb +17 -9
  9. data/lib/space/{app → action}/parser.rb +4 -7
  10. data/lib/space/app.rb +14 -30
  11. data/lib/space/events.rb +27 -20
  12. data/lib/space/events/sources.rb +34 -0
  13. data/lib/space/events/subscription.rb +23 -0
  14. data/lib/space/logger.rb +34 -0
  15. data/lib/space/model.rb +7 -0
  16. data/lib/space/{models → model}/project.rb +4 -10
  17. data/lib/space/{models → model}/project/bundler.rb +7 -8
  18. data/lib/space/model/project/bundler/config.rb +30 -0
  19. data/lib/space/model/repo.rb +38 -0
  20. data/lib/space/{models → model}/repo/bundle.rb +6 -7
  21. data/lib/space/{models → model}/repo/dependency.rb +1 -1
  22. data/lib/space/{models → model}/repo/git.rb +14 -16
  23. data/lib/space/{models → model}/repos.rb +18 -9
  24. data/lib/space/{models → model}/repos/collection.rb +1 -1
  25. data/lib/space/{models → model}/repos/scope.rb +1 -1
  26. data/lib/space/screen.rb +28 -11
  27. data/lib/space/screen/dashboard.rb +21 -5
  28. data/lib/space/screen/progress.rb +16 -5
  29. data/lib/space/screen/view.rb +2 -6
  30. data/lib/space/source.rb +51 -0
  31. data/lib/space/source/command.rb +70 -0
  32. data/lib/space/source/watch.rb +64 -0
  33. data/lib/space/source/watcher.rb +32 -0
  34. data/lib/space/version.rb +1 -1
  35. metadata +27 -24
  36. data/lib/space/app/command.rb +0 -45
  37. data/lib/space/app/command/builtin.rb +0 -43
  38. data/lib/space/app/command/development.rb +0 -60
  39. data/lib/space/app/logger.rb +0 -21
  40. data/lib/space/events/buffer.rb +0 -18
  41. data/lib/space/events/event.rb +0 -14
  42. data/lib/space/models.rb +0 -7
  43. data/lib/space/models/repo.rb +0 -57
  44. data/lib/space/shell.rb +0 -56
  45. data/lib/space/shell/command.rb +0 -63
  46. data/lib/space/shell/watch.rb +0 -50
  47. data/lib/space/shell/watcher.rb +0 -40
@@ -1,15 +1,26 @@
1
1
  module Space
2
2
  class Screen
3
3
  class Progress < View
4
- def render
5
- App.logger.debug('RENDER dashboard')
6
- clear
7
- render_header
4
+ def initialize(*)
5
+ super
6
+ Events.subscribe(self, :start, :update)
8
7
  end
9
8
 
10
9
  def notify(event)
11
- print '.'
10
+ case event
11
+ when :start
12
+ clear
13
+ when :update
14
+ print '.'
15
+ end
12
16
  end
17
+
18
+ private
19
+
20
+ def clear
21
+ move 0, 5
22
+ print "\e[0J" # clear from cursor down
23
+ end
13
24
  end
14
25
  end
15
26
  end
@@ -13,12 +13,8 @@ module Space
13
13
 
14
14
  private
15
15
 
16
- def clear
17
- print "\e[2J\e[0;0H" # clear screen, move cursor to home
18
- end
19
-
20
- def render_header
21
- puts "Project #{project.name}\n\n"
16
+ def move(x, y)
17
+ print "\e[#{y};#{x}H"
22
18
  end
23
19
 
24
20
  def render_template(name, assigns)
@@ -0,0 +1,51 @@
1
+ module Space
2
+ module Source
3
+ autoload :Command, 'space/source/command'
4
+ autoload :Watch, 'space/source/watch'
5
+ autoload :Watcher, 'space/source/watcher'
6
+
7
+ module ClassMethods
8
+ def commands(commands = nil)
9
+ commands ? @commands = commands : @commands
10
+ end
11
+
12
+ def watch(*paths)
13
+ paths.empty? ? (@paths || []) : (@paths = paths)
14
+ end
15
+ end
16
+
17
+ include Events, Watcher
18
+
19
+ class << self
20
+ def included(base)
21
+ base.extend(ClassMethods)
22
+ end
23
+ end
24
+
25
+ attr_reader :results
26
+
27
+ def initialize(path)
28
+ @results = {}
29
+ super
30
+ end
31
+
32
+ def commands
33
+ @commands ||= self.class.commands.inject({}) do |commands, (key, command)|
34
+ commands.merge(key => Command.new(self, key, command))
35
+ end
36
+ end
37
+
38
+ def result(key)
39
+ results[key] || ''
40
+ end
41
+
42
+ def refresh
43
+ commands.each { |key, command| command.refresh }
44
+ end
45
+
46
+ def update(key, result)
47
+ results[key] = result
48
+ notify(:update)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,70 @@
1
+ require 'open3'
2
+ require 'core_ext/string/deansi'
3
+
4
+ module Space
5
+ module Source
6
+ class Command
7
+ class << self
8
+ def execute(dir, command)
9
+ log "#{File.basename(dir)} $ #{command}"
10
+ Open3.capture2e("cd #{dir}; #{command}").first
11
+ end
12
+ end
13
+
14
+ attr_accessor :source, :key, :command
15
+
16
+ def initialize(source, key, command)
17
+ @source = source
18
+ @key = key
19
+ @command = command
20
+ end
21
+
22
+ def refresh
23
+ Thread.new(&method(:run))
24
+ end
25
+
26
+ private
27
+
28
+ def run
29
+ chain.call
30
+ rescue Exception => e
31
+ log e.message, e.backtrace
32
+ end
33
+
34
+ def chain
35
+ @chain ||= filters.reverse.inject(method(:execute)) do |chain, method|
36
+ -> { method.call(&chain) }
37
+ end
38
+ end
39
+
40
+ def execute
41
+ self.class.execute(source.path, command)
42
+ end
43
+
44
+ def filters
45
+ [
46
+ Events.sources.method(:registered),
47
+ method(:update),
48
+ method(:clean),
49
+ ::Bundler.method(:with_clean_env)
50
+ ]
51
+ end
52
+
53
+ def update
54
+ source.update(key, yield)
55
+ end
56
+
57
+ def clean
58
+ strip_ansi(yield.chomp)
59
+ end
60
+
61
+ def chdir(&block)
62
+ Dir.chdir(source.path) { |path| block.call }
63
+ end
64
+
65
+ def strip_ansi(string)
66
+ string.deansi
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,64 @@
1
+ require 'rb-fsevent'
2
+
3
+ module Space
4
+ module Source
5
+ class Watch
6
+ LATENCY = 0.1
7
+ NO_DEFER = FALSE
8
+
9
+ attr_reader :path, :callback, :suspended, :fsevent
10
+
11
+ def initialize(path, &block)
12
+ @path = File.expand_path(path)
13
+ @callback = block
14
+ # @suspended = []
15
+ @fsevent = FSEvent.new
16
+ end
17
+
18
+ def run
19
+ @thread = Thread.new do
20
+ log "WATCHING #{path}"
21
+ watch
22
+ end
23
+ self
24
+ end
25
+
26
+ # def suspended?
27
+ # !suspended.empty?
28
+ # end
29
+
30
+ # def suspend
31
+ # suspended << true
32
+ # end
33
+
34
+ # def unsuspend
35
+ # suspended.pop
36
+ # end
37
+
38
+ private
39
+
40
+ def watch
41
+ fsevent.watch(path, file: file?, latency: LATENCY, no_defer: NO_DEFER) do |paths|
42
+ unless git_dir?(paths)
43
+ log "=> WATCH triggered: #{paths.inspect}"
44
+ fsevent.stop
45
+ callback.call(paths)
46
+ fsevent.run
47
+ end
48
+ end
49
+ fsevent.run
50
+ rescue Exception => e
51
+ puts e.message, e.backtrace
52
+ end
53
+
54
+ def file?
55
+ File.file?(path)
56
+ end
57
+
58
+ def git_dir?(paths)
59
+ paths.size == 1 && File.basename(paths.first) == '.git'
60
+ end
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,32 @@
1
+ module Space
2
+ module Source
3
+ module Watcher
4
+ attr_reader :path
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ start
9
+ end
10
+
11
+ def watched_paths
12
+ @watched_paths ||= self.class.watch.map do |path|
13
+ path[0, 1] == '~' ? path : "#{self.path}/#{path}"
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def start
20
+ watchers.map(&:run)
21
+ end
22
+
23
+ def watchers
24
+ @watchers ||= watched_paths.map do |path|
25
+ Watch.new(path) do |paths|
26
+ refresh
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Space
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: space
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-07 00:00:00.000000000 Z
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: space.
15
15
  email:
@@ -20,37 +20,40 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/core_ext/enumerable/map_slice.rb
23
+ - lib/core_ext/string/deansi.rb
24
+ - lib/core_ext/string/demodulize.rb
23
25
  - lib/core_ext/string/wrap.rb
24
- - lib/space/app/command/builtin.rb
25
- - lib/space/app/command/development.rb
26
- - lib/space/app/command.rb
27
- - lib/space/app/handler.rb
28
- - lib/space/app/logger.rb
29
- - lib/space/app/parser.rb
26
+ - lib/space/action/builtin.rb
27
+ - lib/space/action/development.rb
28
+ - lib/space/action/handler.rb
29
+ - lib/space/action/parser.rb
30
+ - lib/space/action.rb
30
31
  - lib/space/app.rb
31
32
  - lib/space/config.rb
32
- - lib/space/events/buffer.rb
33
- - lib/space/events/event.rb
33
+ - lib/space/events/sources.rb
34
+ - lib/space/events/subscription.rb
34
35
  - lib/space/events.rb
35
36
  - lib/space/helpers.rb
36
- - lib/space/models/project/bundler.rb
37
- - lib/space/models/project.rb
38
- - lib/space/models/repo/bundle.rb
39
- - lib/space/models/repo/dependency.rb
40
- - lib/space/models/repo/git.rb
41
- - lib/space/models/repo.rb
42
- - lib/space/models/repos/collection.rb
43
- - lib/space/models/repos/scope.rb
44
- - lib/space/models/repos.rb
45
- - lib/space/models.rb
37
+ - lib/space/logger.rb
38
+ - lib/space/model/project/bundler/config.rb
39
+ - lib/space/model/project/bundler.rb
40
+ - lib/space/model/project.rb
41
+ - lib/space/model/repo/bundle.rb
42
+ - lib/space/model/repo/dependency.rb
43
+ - lib/space/model/repo/git.rb
44
+ - lib/space/model/repo.rb
45
+ - lib/space/model/repos/collection.rb
46
+ - lib/space/model/repos/scope.rb
47
+ - lib/space/model/repos.rb
48
+ - lib/space/model.rb
46
49
  - lib/space/screen/dashboard.rb
47
50
  - lib/space/screen/progress.rb
48
51
  - lib/space/screen/view.rb
49
52
  - lib/space/screen.rb
50
- - lib/space/shell/command.rb
51
- - lib/space/shell/watch.rb
52
- - lib/space/shell/watcher.rb
53
- - lib/space/shell.rb
53
+ - lib/space/source/command.rb
54
+ - lib/space/source/watch.rb
55
+ - lib/space/source/watcher.rb
56
+ - lib/space/source.rb
54
57
  - lib/space/templates/header.erb
55
58
  - lib/space/templates/repo.erb
56
59
  - lib/space/tmux.rb
@@ -1,45 +0,0 @@
1
- module Space
2
- class App
3
- class Command
4
- autoload :Execute, 'space/app/command/builtin'
5
- autoload :Refresh, 'space/app/command/builtin'
6
- autoload :Scope, 'space/app/command/builtin'
7
- autoload :Unscope, 'space/app/command/builtin'
8
-
9
- autoload :Local, 'space/app/command/development'
10
- autoload :Remote, 'space/app/command/development'
11
-
12
- attr_reader :project, :scope, :args
13
-
14
- def initialize(project, scope, *args)
15
- @project = project
16
- @scope = scope
17
- @args = args
18
- end
19
-
20
- def run
21
- raise 'not implemented'
22
- end
23
-
24
- private
25
-
26
- def repos
27
- @repos ||= project.repos.select_by_names(scope)
28
- end
29
-
30
- def in_scope
31
- repos.each { |repo| yield repo }
32
- end
33
-
34
- def system(cmd)
35
- puts cmd
36
- super
37
- end
38
-
39
- def confirm
40
- puts "\n--- hit any key to continue ---\n"
41
- STDIN.getc
42
- end
43
- end
44
- end
45
- end
@@ -1,43 +0,0 @@
1
- module Space
2
- class App
3
- class Command
4
- class Execute < Command
5
- def run
6
- Bundler.with_clean_env do
7
- in_scope do |repo|
8
- repo.buffering do
9
- puts
10
- repo.execute(*args)
11
- end
12
- end
13
- confirm
14
- end
15
- end
16
- end
17
-
18
- class Refresh < Command
19
- def run
20
- Bundler.with_clean_env do
21
- project.bundler.refresh
22
- in_scope do |repo|
23
- repo.refresh
24
- end
25
- end
26
- end
27
- end
28
-
29
- class Scope < Command
30
- def run
31
- project.repos.scope = repos
32
- end
33
- end
34
-
35
- class Unscope < Command
36
- def run
37
- project.repos.scope = nil
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
@@ -1,60 +0,0 @@
1
- module Space
2
- class App
3
- class Command
4
- class Local < Command
5
- def run
6
- Shell::Watcher.suspend do
7
- repos.each do |repo|
8
- system "bundle config --global local.#{repo.name} #{repo.path}"
9
- end
10
- confirm
11
- end
12
- project.bundler.refresh
13
- end
14
- end
15
-
16
- class Remote < Command
17
- def run
18
- Shell::Watcher.suspend do
19
- repos.each do |repo|
20
- system "bundle config --delete local.#{repo.name}"
21
- end
22
- confirm
23
- end
24
- project.bundler.refresh
25
- end
26
- end
27
-
28
- # class Install < Command
29
- # def run
30
- # in_scope do |repo|
31
- # repo.execute 'bundle install'
32
- # repo.refresh
33
- # end
34
- # end
35
- # end
36
-
37
- # class Update < Command
38
- # def run
39
- # in_scope do |repo|
40
- # repo.execute 'bundle update'
41
- # repo.execute 'git commit -am "bump dependencies"'
42
- # repo.refresh
43
- # end
44
- # end
45
- # end
46
-
47
- # class Checkout < Command
48
- # def run
49
- # # check if branch exists, git co (-b)
50
- # end
51
- # end
52
-
53
- # class PullDeps < Command
54
- # def run
55
- # # pull all dependencies
56
- # end
57
- # end
58
- end
59
- end
60
- end