-
Notifications
You must be signed in to change notification settings - Fork 99
/
Scaffold.pm
53 lines (43 loc) · 1.28 KB
/
Scaffold.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package CPANRatings::Schema::Scaffold;
use Moose;
extends 'Mesoderm';
my %no_serialize = (
reviews => [ qw( module ) ],
review_users => [ qw( id bitcard_id content_suppressed ) ],
);
override column_info => sub {
my ($self, $column) = @_;
my $info = super;
if ($column->{data_type} =~ m/(DATE|TIME)/) {
$info->{timezone} = 'UTC';
}
if (my $columns = $no_serialize{ $column->table->name } ) {
my $column_name = $column->name;
$info->{is_serializable} = 0
if grep { $_ eq $column_name } @$columns;
}
$info->{is_serializable} = 1
if $column->name eq 'review' and $column->table->name eq 'reviews';
return $info;
};
sub ignore_table {
my ($self, $table) = @_;
return 1 if $table->name =~ m/_old$/;
return 0 if $table->name =~ m/^review/;
return 1;
}
override 'table_moniker' => sub { __accessor(@_) };
override 'relationship_accessor' => sub { __accessor(@_) };
override 'mapping_accessor' => sub { __accessor(@_) };
sub __accessor {
my $a = super;
$a =~ s/reviews?_//;
return $a;
}
override table_components => sub {
my ($self, $table) = @_;
my @components = super;
push @components, 'Helper::Row::ToJSON', 'InflateColumn::DateTime';
return @components;
};
1;