Navigation Menu

Skip to content

Commit

Permalink
Introduce new option to disable completion
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 16, 2015
1 parent c6395ca commit 03fb4f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
8 changes: 7 additions & 1 deletion bin/droonga-request
Expand Up @@ -32,6 +32,7 @@ options = {
:receiver_port => 0,
:report_request => false,
:report_elapsed_time => true,
:completion => true,
:validation => true,
}

Expand Down Expand Up @@ -99,7 +100,12 @@ parser.on("--[no-]report-elapsed-time",
options[:report_elapsed_time] = report_elapsed_time
end
parser.separator("")
parser.separator("Misc:")
parser.separator("Messages:")
parser.on("--[no-]completion",
"Do completion of required fields for input message or not.",
"(#{options[:completion]})") do |completion|
options[:completion] = completion
end
parser.on("--[no-]validation",
"Do validation for input message or not.",
"(#{options[:validation]})") do |validation|
Expand Down
9 changes: 8 additions & 1 deletion bin/droonga-send
Expand Up @@ -28,6 +28,7 @@ options.report_throughput = false
options.default_protocol = "droonga"
options.default_port = 10031
options.default_tag = "droonga"
options.completion = true
options.validation = true

servers = []
Expand Down Expand Up @@ -58,6 +59,7 @@ def parse_server(server, options)
:port => Integer(port),
:protocol => protocol.to_sym,
:tag => tag,
:completion => options.completion,
:validation => options.validation,
}
end
Expand Down Expand Up @@ -141,7 +143,12 @@ parser.on("--report-throughput",
options.report_throughput = true
end
parser.separator("")
parser.separator("Misc:")
parser.separator("Messages:")
parser.on("--[no-]completion",
"Do completion of required fields for input message or not.",
"(#{options.completion})") do |completion|
options.completion = completion
end
parser.on("--[no-]validation",
"Do validation for input message or not.",
"(#{options.validation})") do |validation|
Expand Down
7 changes: 5 additions & 2 deletions doc/text/news.md
Expand Up @@ -2,10 +2,13 @@

## 0.2.1: 2005-01-29 (planned)

* Required fields of input messages are automatically completed by default.
* Input messages are automatically validated by default.
* droonga-send, droonga-request:
A new option `--[no-]validation` is introduced.
You should specify `--no-validation` to skip validation.
* A new option `--[no-]completion` is introduced.
You should specify `--no-completion` to send incomplete messages intentionally.
* A new option `--[no-]validation` is introduced.
You should specify `--no-validation` to send invalid messages intentionally.

## 0.2.0: 2014-11-29

Expand Down
12 changes: 8 additions & 4 deletions lib/droonga/client.rb
Expand Up @@ -62,30 +62,34 @@ def open(options={})
# @option options [Integer] :timeout (5)
# The timeout value for connecting to, writing to and reading
# from Droonga Engine.
# @option options [Boolean] :completion (true)
# Do or do not complete required fields of input messages.
# @option options [Boolean] :validation (true)
# Do or do not validate input messages.
def initialize(options={})
@connection = create_connection(options)
@completer = MessageCompleter.new
unless options[:completion] == false
@completer = MessageCompleter.new
end
unless options[:validation] == false
@validator = MessageValidator.new
end
end

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

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

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

0 comments on commit 03fb4f8

Please sign in to comment.