Class: Groonga::Command::Base
- Inherits:
-
Object
- Object
- Groonga::Command::Base
show all
- Defined in:
- lib/groonga/command/base.rb
Direct Known Subclasses
ColumnCreate, ColumnRemove, ColumnRename, Delete, Get, Load, Register, Select, Suggest, TableCreate, TableRemove, TableRename, Truncate
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, pair_arguments, ordered_arguments = []) ⇒ Base
Returns a new instance of Base.
44
45
46
47
48
49
|
# File 'lib/groonga/command/base.rb', line 44
def initialize(name, pair_arguments, ordered_arguments=[])
@name = name
@arguments = construct_arguments(pair_arguments, ordered_arguments)
@original_format = nil
@original_source = nil
end
|
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
42
43
44
|
# File 'lib/groonga/command/base.rb', line 42
def arguments
@arguments
end
|
#name ⇒ Object
Returns the value of attribute name.
42
43
44
|
# File 'lib/groonga/command/base.rb', line 42
def name
@name
end
|
Returns the value of attribute original_format.
43
44
45
|
# File 'lib/groonga/command/base.rb', line 43
def original_format
@original_format
end
|
#original_source ⇒ Object
Returns the value of attribute original_source.
43
44
45
|
# File 'lib/groonga/command/base.rb', line 43
def original_source
@original_source
end
|
Class Method Details
.parameter_names ⇒ Object
37
38
39
|
# File 'lib/groonga/command/base.rb', line 37
def parameter_names
[]
end
|
Instance Method Details
#==(other) ⇒ Object
63
64
65
66
67
|
# File 'lib/groonga/command/base.rb', line 63
def ==(other)
other.is_a?(self.class) and
@name == other.name and
@arguments == other.arguments
end
|
#[](name) ⇒ Object
51
52
53
|
# File 'lib/groonga/command/base.rb', line 51
def [](name)
@arguments[normalize_name(name)]
end
|
#[]=(name, value) ⇒ Object
55
56
57
|
# File 'lib/groonga/command/base.rb', line 55
def []=(name, value)
@arguments[normalize_name(name)] = value
end
|
73
74
75
|
# File 'lib/groonga/command/base.rb', line 73
def command_format?
@original_format == :command
end
|
#has_key?(name) ⇒ Boolean
59
60
61
|
# File 'lib/groonga/command/base.rb', line 59
def has_key?(name)
@arguments.has_key?(normalize_name(name))
end
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/groonga/command/base.rb', line 95
def to_command_format
command_line = [@name]
sorted_arguments = @arguments.sort_by do |name, _|
name.to_s
end
sorted_arguments.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
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/groonga/command/base.rb', line 77
def to_uri_format
path = "/d/#{@name}"
arguments = @arguments.dup
output_type = arguments.delete(:output_type)
path << ".#{output_type}" if output_type
unless arguments.empty?
sorted_arguments = arguments.sort_by do |name, _|
name.to_s
end
uri_arguments = sorted_arguments.collect do |name, value|
"#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
end
path << "?"
path << uri_arguments.join("&")
end
path
end
|
69
70
71
|
# File 'lib/groonga/command/base.rb', line 69
def uri_format?
@original_format == :uri
end
|