Make the tests pass again
[catagits/Gitalist.git] / lib / Gitalist / Git / CollectionOfRepositories / FromListOfDirectories.pm
1 use MooseX::Declare;
2
3 class Gitalist::Git::CollectionOfRepositories::FromListOfDirectories with Gitalist::Git::CollectionOfRepositories {
4     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
5     use MooseX::Types::Moose qw/ ArrayRef HashRef /;
6     use MooseX::Types::Path::Class qw/Dir/;
7     use Gitalist::Git::Types qw/ ArrayRefOfDirs /;
8     use File::Basename qw/basename/;
9     use Path::Class qw/dir/;
10     use Moose::Autobox;
11
12     has repos => (
13         isa => ArrayRefOfDirs,
14         is => 'ro',
15         coerce => 1,
16         required => 1,
17     );
18     has _repos_by_name => (
19         isa => HashRef[Dir],
20         is => 'ro',
21         lazy_build => 1,
22         traits => ['Hash'],
23         handles => {
24             _get_path_for_repository_name => 'get',
25         },
26     );
27
28     method _build__repos_by_name {
29         +{ map { basename($_) => dir($_) } $self->repos->flatten };
30     }
31
32     method _get_repo_from_name (NonEmptySimpleStr $name) {
33         return Gitalist::Git::Repository->new($self->_get_path_for_repository_name($name));
34     }
35
36     ## Builders
37     method _build_repositories {
38         [ map { $self->get_repository(basename($_)) } $self->repos->flatten ];
39     }
40 }                               # end class
41
42 1;
43
44 =head1 NAME
45
46 Gitalist::Git::CollectionOfRepositories::FromListOfDirectories - Model of a collection of git repositories
47
48 =head1 SYNOPSIS
49
50     my $collection = Gitalist::Git::CollectionOfRepositories::FromListOfDirectories->new( repos => [qw/
51         /path/to/repos1
52         /path/to/repos2
53     /] );
54     my $repository_list = $collection->repositories;
55     my $first_repository = $repository_list->[0];
56     my $named_repository = $repo->get_repository('Gitalist');
57
58 =head1 DESCRIPTION
59
60 This class provides an abstraction for a list of Repository directories.
61
62 =head1 ATTRIBUTES
63
64 =head2 repos (C<< ArrayRef[NonEmptySimpleStr] >>)
65
66 A list of git repository directories
67
68 =head1 SEE ALSO
69
70 L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository>
71
72 =head1 AUTHORS
73
74 See L<Gitalist> for authors.
75
76 =head1 LICENSE
77
78 See L<Gitalist> for the license.
79
80 =cut