Sha256: c6f5faf9c7e0b715bff750bce884d4cade82e335f69aee4025d720143f15ebd3

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

module Space
  module Model
    class Repos
      autoload :Collection, 'space/model/repos/collection'

      attr_accessor :project, :paths, :scope

      def initialize(project, paths)
        @project = project
        @paths = paths
      end

      def all
        @all ||= Collection.new(self, paths.map { |path| Repo.new(project, path) })
      end

      def names
        @names ||= all.map(&:name)
      end

      def scope=(scope)
        log "SCOPE: #{scope ? scope.map(&:name) : '-'}"
        @scope = scope
      end

      def scope
        @scope || all
      end

      def scoped?
        !!@scope
      end

      def find_by_name_or_number(repo)
        repo =~ /^\d+$/ ? find_by_number(repo.to_i) : find_by_name(repo)
      end

      def find_by_name(name)
        all.detect { |repo| repo.name == name } || raise("cannot find repo by name #{name.inspect}")
      end

      def find_by_number(number)
        all.detect { |repo| repo.number == number } || raise("cannot find repo by number #{number.inspect}")
      end

      def select_by_names_or_numbers(repos)
        Collection.new(self, repos.map { |repo| find_by_name_or_number(repo) })
      end

      def select_by_names(names)
        Collection.new(self, all.select { |repo| names.include?(repo.name) })
      end

      def refresh
        all.each(&:refresh)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
space-0.0.9 lib/space/model/repos.rb
space-0.0.8 lib/space/model/repos.rb
space-0.0.7 lib/space/model/repos.rb
space-0.0.6 lib/space/model/repos.rb