lib/space/models/repos.rb in space-0.0.3 vs lib/space/models/repos.rb in space-0.0.4
- old
+ new
@@ -1,45 +1,50 @@
module Space
- class Repos < Array
- class << self
+ module Models
+ class Repos
+ include Events
+
+ autoload :Collection, 'space/models/repos/collection'
+
+ attr_accessor :project, :paths, :scope
+
+ def initialize(project, paths)
+ @project = project
+ @paths = paths
+ end
+
def all
- @all ||= create(App.config.paths)
+ @all ||= Collection.new(self, paths.map { |path| Repo.new(project, path) })
end
def names
@names ||= all.map(&:name)
end
- def select(names)
- new(all.select { |repo| names.include?(repo.name) })
+ def scope=(scope)
+ @scope = scope
+ notify(:update, nil)
end
- def find_by_name(name)
- all.find_by_name(name)
+ def scope
+ @scope || all
end
- def create(paths)
- new(paths.map_with_index { |path, ix| Repo.new(ix + 1, path) })
+ def scoped?
+ !!@scope
end
- end
- def names
- map(&:name)
- end
+ def find_by_name(name)
+ all.detect { |repo| repo.name == name } || raise("cannot find repo #{name.inspect}")
+ end
- def scoped?
- size != self.class.all.size
- end
+ def select_by_names(names)
+ Collection.new(self, all.select { |repo| names.include?(repo.name) })
+ end
- # def name
- # "#{App.name}-(#{names.join('|').gsub("#{App.config.name}-", '')})"
- # end
-
- def find_by_name(name)
- detect { |repo| repo.name == name }
- end
-
- def self_and_dependencies
- self.class.new(map { |repo| [repo] + repo.dependencies }.flatten.uniq)
+ def subscribe(*args)
+ super
+ all.each { |repo| repo.subscribe(*args) }
+ end
end
end
end