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