File Coverage

blib/lib/Arango/Tango/Collection.pm
Criterion Covered Total %
statement 10 29 34.4
branch 0 4 0.0
condition 0 2 0.0
subroutine 4 12 33.3
pod 7 7 100.0
total 21 54 38.8


line stmt bran cond sub pod time code
1             # ABSTRACT: ArangoDB Collection object
2             package Arango::Tango::Collection;
3             $Arango::Tango::Collection::VERSION = '0.018';
4 5     5   36 use warnings;
  5         10  
  5         163  
5 5     5   26 use strict;
  5         9  
  5         158  
6              
7 5     5   33 use Arango::Tango::API;
  5         10  
  5         1173  
8              
9             BEGIN {
10 5     5   283 Arango::Tango::API::_install_methods "Arango::Tango::Collection" => {
11              
12             ## Document Management -- Keeping here for now.
13             delete_document => {
14             rest => [ delete => '{{database}}_api/document/{name}/{key}'],
15             inject_properties => ['database', 'name'],
16             signature => ['key'],
17             ## FIXME - Header parameters still not supported
18             },
19              
20             document => {
21             rest => [ get => '{{database}}_api/document/{name}/{key}' ],
22             inject_properties => [ 'database', 'name' ],
23             signature => ['key'],
24             ## FIXME - Header parameters still not supported
25             },
26              
27             ## Collection Management
28             load_indexes => {
29             rest => [ put => '{{database}}_api/collection/{name}/loadIndexesIntoMemory' ],
30             inject_properties => [ 'database', 'name' ],
31             },
32              
33             rename => {
34             rest => [ put => '{{database}}_api/collection/{collection}/rename' ],
35             inject_properties => [ 'database', { prop => 'name', as => 'collection' } ],
36             signature => [ 'name' ],
37             schema => { name => { type => 'string' }},
38             },
39              
40             properties => {
41             rest => [ get => '{{database}}_api/collection/{name}/properties' ],
42             inject_properties => ['database', 'name' ],
43             },
44              
45             truncate => {
46             rest => [ put => '{{database}}_api/collection/{name}/truncate' ],
47             inject_properties => [ 'database', 'name' ]
48             },
49              
50             revision => {
51             rest => [ get => '{{database}}_api/collection/{name}/revision' ],
52             inject_properties => [ 'database', 'name' ],
53             },
54              
55             info => {
56             rest => [ get => '{{database}}_api/collection/{name}' ],
57             inject_properties => [ 'database', 'name' ],
58             },
59              
60             recalculate_count => {
61             rest => [ put => '{{database}}_api/collection/{name}/recalculateCount' ],
62             inject_properties => [ 'database', 'name' ],
63             },
64              
65             rotate => {
66             rest => [ put => '{{database}}_api/collection/{name}/rotate' ],
67             inject_properties => [ 'database', 'name' ],
68             },
69              
70             figures => {
71             rest => [ get => '{{database}}_api/collection/{name}/figures' ],
72             schema => { withRevisions => { type => 'boolean' }, withData => {type=>'boolean' }},
73             inject_properties => [ 'database', 'name' ],
74             },
75              
76             count => {
77             rest => [ get => '{{database}}_api/collection/{name}/count' ],
78             schema => { withRevisions => { type => 'boolean' }, withData => {type=>'boolean' }},
79             inject_properties => [ 'database', 'name' ],
80             },
81              
82              
83             checksum => {
84             rest => [ get => '{{database}}_api/collection/{name}/checksum' ],
85             schema => { withRevisions => { type => 'boolean' }, withData => {type=>'boolean' }},
86             inject_properties => [ 'database', 'name' ],
87             },
88              
89             set_properties => {
90             rest => [ put => '{{database}}_api/collection/{name}/properties'],
91             schema => { waitForSync => { type => 'boolean' }, journalSize => { type => 'integer' }},
92             inject_properties => [ 'database', 'name' ],
93             },
94              
95             };
96             }
97              
98              
99              
100             sub _new {
101 0     0     my ($class, %opts) = @_;
102 0           return bless {%opts} => $class;
103             }
104              
105             sub bulk_import {
106 0     0 1   my ($self, $documents, %options) = @_;
107 0   0       $options{type} ||= "list";
108             return $self->{arango}->_api( bulk_import_list => {
109             database => $self->{database},
110             collection => $self->{name},
111 0           _body => $documents,
112             _url_parameters => \%options
113             })
114             }
115              
116             sub document_paths {
117 0     0 1   my ($self) = @_;
118             return $self->{arango}->_api( all_keys => { database => $self->{database}, collection => $self->{name}, type => "path"})->{result}
119 0           }
120              
121             sub create_document {
122 0     0 1   my ($self, $body) = @_;
123 0 0         die "Arango::Tango | Refusing to store undefined body" unless defined($body);
124 0           return $self->{arango}->_api( create_document => { database => $self->{database}, collection => $self->{name}, _body => $body})
125             }
126              
127             sub replace_document {
128 0     0 1   my ($self, $key, $body) = @_;
129 0 0         die "Arango::Tango | Refusing to store undefined body" unless defined($body);
130 0           return $self->{arango}->_api( replace_document => { database => $self->{database}, collection => $self->{name}, key => $key, _body => $body})
131             }
132              
133             sub get_access_level {
134 0     0 1   my ($self, $username) = @_;
135 0           return $self->{arango}->get_access_level( $username, $self->{database}, $self->{name} );
136             }
137              
138             sub clear_access_level {
139 0     0 1   my ($self, $username) = @_;
140 0           return $self->{arango}->clear_access_level( $username , $self->{database}, $self->{name} );
141             }
142              
143             sub set_access_level {
144 0     0 1   my ($self, $username, $grant) = @_;
145 0           return $self->{arango}->set_access_level($username, $grant, $self->{database}, $self->{name});
146             }
147              
148              
149             1;
150              
151             __END__