Class: Groonga::QueryLog::Command
- Inherits:
-
Object
- Object
- Groonga::QueryLog::Command
- Defined in:
- lib/groonga/query-log.rb
Direct Known Subclasses
Constant Summary collapse
- @@registered_commands =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_format ⇒ Object
Returns the value of attribute original_format.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #command_format? ⇒ Boolean
-
#initialize(name, parameters) ⇒ Command
constructor
A new instance of Command.
- #to_command_format ⇒ Object
- #to_uri_format ⇒ Object
- #uri_format? ⇒ Boolean
Constructor Details
#initialize(name, parameters) ⇒ Command
Returns a new instance of Command.
73 74 75 76 77 |
# File 'lib/groonga/query-log.rb', line 73 def initialize(name, parameters) @name = name @parameters = parameters @original_format = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
71 72 73 |
# File 'lib/groonga/query-log.rb', line 71 def name @name end |
#original_format ⇒ Object
Returns the value of attribute original_format.
72 73 74 |
# File 'lib/groonga/query-log.rb', line 72 def original_format @original_format end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
71 72 73 |
# File 'lib/groonga/query-log.rb', line 71 def parameters @parameters end |
Class Method Details
.parse(input) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/groonga/query-log.rb', line 31 def parse(input) if input.start_with?("/d/") parse_uri_path(input) else parse_command_line(input) end end |
.register(name, klass) ⇒ Object
27 28 29 |
# File 'lib/groonga/query-log.rb', line 27 def register(name, klass) @@registered_commands[name] = klass end |
Instance Method Details
#==(other) ⇒ Object
79 80 81 82 83 |
# File 'lib/groonga/query-log.rb', line 79 def ==(other) other.is_a?(self.class) and @name == other.name and @parameters == other.parameters end |
#command_format? ⇒ Boolean
89 90 91 |
# File 'lib/groonga/query-log.rb', line 89 def command_format? @original_format == :command end |
#to_command_format ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/groonga/query-log.rb', line 111 def to_command_format command_line = [@name] sorted_parameters = @parameters.sort_by do |name, _| name.to_s end sorted_parameters.each do |name, value| escaped_value = value.gsub(/[\n"\\]/) do special_character = $MATCH case special_character when "\n" "\\n" else "\\#{special_character}" end end command_line << "--#{name}" command_line << "\"#{escaped_value}\"" end command_line.join(" ") end |
#to_uri_format ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/groonga/query-log.rb', line 93 def to_uri_format path = "/d/#{@name}" parameters = @parameters.dup output_type = parameters.delete("output_type") path << ".#{output_type}" if output_type unless parameters.empty? sorted_parameters = parameters.sort_by do |name, _| name.to_s end uri_parameters = sorted_parameters.collect do |name, value| "#{CGI.escape(name)}=#{CGI.escape(value)}" end path << "?" path << uri_parameters.join("&") end path end |
#uri_format? ⇒ Boolean
85 86 87 |
# File 'lib/groonga/query-log.rb', line 85 def uri_format? @original_format == :uri end |