Navigation Menu

Skip to content

Commit

Permalink
Allow to enable/disable completion and validation for each message
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 16, 2015
1 parent 03fb4f8 commit 4a58b5b
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions lib/droonga/client.rb
Expand Up @@ -68,29 +68,29 @@ def open(options={})
# Do or do not validate input messages.
def initialize(options={})
@connection = create_connection(options)
unless options[:completion] == false
@completer = MessageCompleter.new
end
unless options[:validation] == false
@validator = MessageValidator.new
end

@completion = options[:completion] != false
@validation = options[:validation] != false

@completer = MessageCompleter.new
@validator = MessageValidator.new
end

def send(message, options={}, &block)
message = @completer.complete(message) if @completer
@validator.validate(message) if @validator
message = do_completion(message, options)
do_validation(message, options)
@connection.send(message, options, &block)
end

def request(message, options={}, &block)
message = @completer.complete(message) if @completer
@validator.validate(message) if @validator
message = do_completion(message, options)
do_validation(message, options)
@connection.request(message, options, &block)
end

def subscribe(message, options={}, &block)
message = @completer.complete(message) if @completer
@validator.validate(message) if @validator
message = do_completion(message, options)
do_validation(message, options)
@connection.subscribe(message, options, &block)
end

Expand All @@ -111,5 +111,23 @@ def create_connection(options)
Connection::DroongaProtocol.new(options)
end
end

def do_completion(message, options={})
if options[:completion].nil?
return message unless @completion
else
return message if options[:completion] == false
end
@completer.complete(message)
end

def do_validation(message, options={})
if options[:validation].nil?
return unless @validation
else
return if options[:validation] == false
end
@validator.validate(message)
end
end
end

0 comments on commit 4a58b5b

Please sign in to comment.