lib/space/models/repo.rb in space-0.0.3 vs lib/space/models/repo.rb in space-0.0.4
- old
+ new
@@ -1,40 +1,57 @@
module Space
- class Repo
- attr_reader :number, :path, :git, :bundle
+ module Models
+ class Repo
+ autoload :Bundle, 'space/models/repo/bundle'
+ autoload :Dependency, 'space/models/repo/dependency'
+ autoload :Git, 'space/models/repo/git'
- def initialize(number, path)
- @number = number
- @path = File.expand_path(path)
- @git = Git.new(path)
- @bundle = Bundle.new(path)
- end
+ include Events
- def name
- @name ||= File.basename(path)
- end
+ attr_reader :project, :path, :git, :bundle
- def ref
- git.commit
- end
+ def initialize(project, path)
+ @project = project
+ @path = File.expand_path(path)
+ @git = Git.new(self)
+ @bundle = Bundle.new(self, project.repos)
+ end
- def dependencies
- Repos.select(bundle.deps.map(&:name))
- end
+ def name
+ @name ||= File.basename(path)
+ end
- def reset
- git.reset
- bundle.reset
- end
+ def number
+ @number ||= project.number(name)
+ end
- def execute(cmd)
- chdir do
- puts "in #{path}".ansi(:bold, :yellow)
- system(cmd)
+ def ref
+ git.commit
end
- end
- def chdir(&block)
- Dir.chdir(path, &block)
+ def deps
+ bundle.deps
+ end
+
+ def refresh
+ git.refresh
+ bundle.refresh
+ end
+
+ def execute(cmd)
+ chdir do
+ puts "in #{path}".ansi(:bold, :yellow)
+ system(cmd)
+ end
+ end
+
+ def chdir(&block)
+ Dir.chdir(path, &block)
+ end
+
+ def subscribe(*args)
+ super
+ [git, bundle].each { |object| object.subscribe(self) }
+ end
end
end
end