Skip to content

Commit

Permalink
Validate key_type as a required parameter for some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 7, 2014
1 parent 15c2aca commit 6d31cb0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/droonga/plugins/groonga/table_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def process_request(request)
:result => false)
end

validate_key_type

options = parse_command
::Groonga::Schema.define(:context => @context) do |schema|
schema.create_table(name, options)
Expand Down Expand Up @@ -88,6 +90,29 @@ def parse_normalizer(options)
return unless @command["normalizer"]
options[:normalizer] = @command["normalizer"]
end

def validate_key_type
if @command.table_hash_key? and @command["key_type"].nil?
message = "key_type is required for TABLE_HASH_KEY table"
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
:message => message,
:result => false)
end

if @command.table_pat_key? and @command["key_type"].nil?
message = "key_type is required for TABLE_PAT_KEY table"
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
:message => message,
:result => false)
end

if @command.table_dat_key? and @command["key_type"].nil?
message = "key_type is required for TABLE_DAT_KEY table"
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
:message => message,
:result => false)
end
end
end

class Handler < Droonga::Handler
Expand Down

0 comments on commit 6d31cb0

Please sign in to comment.