Commit | Line | Data |
576d59a0 |
1 | use MooseX::Declare; |
2 | |
31d3c368 |
3 | class Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive { |
5264023a |
4 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
5 | use MooseX::Types::Path::Class qw/Dir/; |
6 | |
7 | use Moose::Autobox; |
8 | use List::Util 'first'; |
9 | |
10 | has repo_dir => ( |
576d59a0 |
11 | isa => Dir, |
12 | is => 'ro', |
13 | required => 1, |
14 | coerce => 1, |
5264023a |
15 | ); |
576d59a0 |
16 | |
13c42902 |
17 | method debug_string { 'repository directory ' . $self->repo_dir } |
18 | |
576d59a0 |
19 | method BUILD { |
309cee4f |
20 | # Make sure repo_dir is an absolute path so that ->contains() works correctly. |
411e6add |
21 | $self->repo_dir->resolve; |
576d59a0 |
22 | } |
23 | |
5264023a |
24 | method _find_repos(Dir $dir) { |
25 | return map { |
26 | $self->_is_git_repo($_) ? $_ : $self->_find_repos($_) |
27 | } grep $_->is_dir, $dir->children; |
28 | } |
29 | |
52d3a5d0 |
30 | method _get_repo_from_name (NonEmptySimpleStr $name) { |
5264023a |
31 | my $repo = first { $_->name eq $name } $self->repositories->flatten |
32 | or return; |
52d3a5d0 |
33 | return $repo; |
576d59a0 |
34 | } |
35 | |
634770da |
36 | method _get_repo_name (NonEmptySimpleStr $name) { |
37 | # strip off the repo_dir part from a path |
52d3a5d0 |
38 | return Path::Class::Dir->new($name)->relative($self->repo_dir)->stringify; |
634770da |
39 | } |
40 | |
576d59a0 |
41 | ## Builders |
42 | method _build_repositories { |
5264023a |
43 | return [ |
634770da |
44 | map { Gitalist::Git::Repository->new($_, $self->_get_repo_name("$_")) } $self->_find_repos( $self->repo_dir ) |
5264023a |
45 | ]; |
576d59a0 |
46 | } |
31d3c368 |
47 | with 'Gitalist::Git::CollectionOfRepositories'; |
e473ebf6 |
48 | } # end class |
576d59a0 |
49 | |
50 | __END__ |
51 | |
52 | =head1 NAME |
53 | |
54 | Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive - Model of recursive directories containing git repositories |
55 | |
56 | =head1 SYNOPSIS |
57 | |
58 | my $repo = Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive->new( repo_dir => $Dir ); |
59 | my $repository_list = $repo->repositories; |
60 | my $first_repository = $repository_list->[0]; |
61 | my $named_repository = $repo->get_repository('Gitalist'); |
62 | |
63 | =head1 DESCRIPTION |
64 | |
65 | This class provides a list of Repositories recursively found in the given directory. |
66 | |
67 | =head1 ATTRIBUTES |
68 | |
69 | =head2 repo_dir (C<Path::Class::Dir>) |
70 | |
71 | The filesystem root of the C<Repo>. |
72 | |
73 | =head1 SEE ALSO |
74 | |
75 | L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository> |
76 | |
77 | =head1 AUTHORS |
78 | |
79 | See L<Gitalist> for authors. |
80 | |
81 | =head1 LICENSE |
82 | |
83 | See L<Gitalist> for the license. |
84 | |
85 | =cut |