[Groonga-commit] droonga/fluent-plugin-droonga at 8a57580 [master] Validate effective_date

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Feb 12 17:00:34 JST 2014


YUKI Hiroshi	2014-02-12 17:00:34 +0900 (Wed, 12 Feb 2014)

  New Revision: 8a57580444a14b12a76ea2635d2d8ddbb357efa7
  https://github.com/droonga/fluent-plugin-droonga/commit/8a57580444a14b12a76ea2635d2d8ddbb357efa7

  Message:
    Validate effective_date

  Modified files:
    lib/droonga/catalog/base.rb

  Modified: lib/droonga/catalog/base.rb (+22 -0)
===================================================================
--- lib/droonga/catalog/base.rb    2014-02-12 16:23:36 +0900 (06a0e62)
+++ lib/droonga/catalog/base.rb    2014-02-12 17:00:34 +0900 (560bd5e)
@@ -15,6 +15,7 @@
 
 require "digest/sha1"
 require "zlib"
+require "time"
 require "droonga/message_processing_error"
 
 module Droonga
@@ -41,6 +42,13 @@ module Droonga
       end
     end
 
+    class InvalidDate < ValidationError
+      def initialize(name, value, path)
+        super("\"#{name}\" must be a valid datetime. " +
+                "\"#{value}\" cannot be parsed as a datetime.", path)
+      end
+    end
+
     class NegativeNumber < ValidationError
       def initialize(name, actual, path)
         super("\"#{name}\" must be a positive number, but #{actual}.", path)
@@ -60,6 +68,7 @@ module Droonga
         @path = path
         @base_path = File.dirname(path)
 
+        validate_effective_date
         validate_zones
         validate_farms
         validate_datasets
@@ -189,6 +198,15 @@ module Droonga
         end
       end
 
+      def validate_valid_datetime(value, name)
+        validate_parameter_type(String, value, name)
+        begin
+          Time.parse(value)
+        rescue ArgumentError => error
+          raise InvalidDate.new(name, value, @path)
+        end
+      end
+
       def validate_positive_numeric_parameter(value, name)
         validate_parameter_type(Numeric, value, name)
         if value < 0
@@ -210,6 +228,10 @@ module Droonga
         end
       end
 
+      def validate_effective_date
+        validate_valid_datetime(@data["effective_date"], "effective_date")
+      end
+
       def validate_zones
         zones = @data["zones"]
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index