[Bps-public-commit] r17226 - Prophet/branches/actions/lib/Prophet
jesse at bestpractical.com
jesse at bestpractical.com
Mon Dec 15 02:45:49 EST 2008
Author: jesse
Date: Mon Dec 15 02:45:49 2008
New Revision: 17226
Modified:
Prophet/branches/actions/lib/Prophet/Record.pm
Log:
* extracted validation and recommended values features from sd to Prophet::Record
Modified: Prophet/branches/actions/lib/Prophet/Record.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Record.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Record.pm Mon Dec 15 02:45:49 2008
@@ -148,7 +148,6 @@
my $self = shift;
my $collection = $collection_class->new(
app_handle => $self->app_handle,
- type => $collection_class->record_class->type,
);
$collection->matching( sub { ($_[0]->prop( $args{by} )||'') eq $self->uuid }
);
@@ -547,6 +546,39 @@
return $self->handle->uuid;
}
+
+sub validate_prop_from_recommended_values {
+ my $self = shift;
+ my $prop = shift;
+ my $args = shift;
+
+ if ( my @options = $self->recommended_values_for_prop($prop) ) {
+ return 1 if scalar grep { $args->{props}{$prop} eq $_ } @options;
+
+ $args->{errors}{$prop}
+ = "'" . $args->{props}->{$prop} . "' is not a valid $prop";
+ return 0;
+ }
+ return 1;
+
+}
+
+
+sub recommended_values_for_prop {
+ my $self = shift;
+ my $prop = shift;
+
+ if (my $code = $self->can("_recommended_values_for_prop_".$prop)) {
+ $code->($self, @_);
+ } else {
+ return undef;
+ }
+
+}
+
+
+
+
=head2 _default_summary_format
A string of the default summary format for record types that do not
More information about the Bps-public-commit
mailing list