Class: Groonga::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/command/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pair_arguments, ordered_arguments = {}) ⇒ Base #initialize(command_name, pair_arguments, ordered_arguments = {}) ⇒ Base

Returns a new instance of Base.

Overloads:

  • #initialize(pair_arguments, ordered_arguments = {}) ⇒ Base

    Initializes a new known command. The command class must implement #command_name method.

    Parameters:

    • pair_arguments (::Hash<String, String>)

      The list of pair arguments.

    • ordered_arguments (::Array<String>) (defaults to: {})

      The list of ordered arguments.

    Since:

    • 1.2.3

  • #initialize(command_name, pair_arguments, ordered_arguments = {}) ⇒ Base

    Initializes a new unknown command.

    Parameters:

    • command_name (String)

      The command name.

    • pair_arguments (::Hash<String, String>)

      The list of pair arguments.

    • ordered_arguments (::Array<String>) (defaults to: {})

      The list of ordered arguments.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/groonga/command/base.rb', line 85

def initialize(arg1=nil, arg2=nil, arg3=nil)
  case arg1
  when String, Symbol
    command_name = arg1.to_s
    pair_arguments = arg2
    ordered_arguments = arg3
  else
    command_name = self.class.command_name
    pair_arguments = arg1
    ordered_arguments = arg2
  end
  pair_arguments ||= {}
  ordered_arguments ||= []

  @command_name = command_name
  @arguments = construct_arguments(pair_arguments, ordered_arguments)
  @original_format = nil
  @original_source = nil
  @path_prefix = "/d/"
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



60
61
62
# File 'lib/groonga/command/base.rb', line 60

def arguments
  @arguments
end

#command_nameString (readonly)

Returns The command name.

Returns:

  • (String)

    The command name.

Since:

  • 1.1.8



59
60
61
# File 'lib/groonga/command/base.rb', line 59

def command_name
  @command_name
end

#original_formatObject

Returns the value of attribute original_format.



61
62
63
# File 'lib/groonga/command/base.rb', line 61

def original_format
  @original_format
end

#original_sourceObject

Returns the value of attribute original_source.



61
62
63
# File 'lib/groonga/command/base.rb', line 61

def original_source
  @original_source
end

#path_prefixObject

Returns the value of attribute path_prefix.



61
62
63
# File 'lib/groonga/command/base.rb', line 61

def path_prefix
  @path_prefix
end

Class Method Details

.parameter_namesObject



51
52
53
# File 'lib/groonga/command/base.rb', line 51

def parameter_names
  []
end

Instance Method Details

#==(other) ⇒ Object



124
125
126
127
128
# File 'lib/groonga/command/base.rb', line 124

def ==(other)
  other.is_a?(self.class) and
    @command_name == other.command_name and
    @arguments == other.arguments
end

#[](name) ⇒ Object



111
112
113
# File 'lib/groonga/command/base.rb', line 111

def [](name)
  @arguments[normalize_name(name)]
end

#[]=(name, value) ⇒ Object



115
116
117
# File 'lib/groonga/command/base.rb', line 115

def []=(name, value)
  @arguments[normalize_name(name)] = value
end

#command_format?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/groonga/command/base.rb', line 134

def command_format?
  @original_format == :command
end

#key?(name) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


119
120
121
# File 'lib/groonga/command/base.rb', line 119

def key?(name)
  @arguments.key?(normalize_name(name))
end

#nameObject

Deprecated.

since 1.1.8. Use #command_name instead.



107
108
109
# File 'lib/groonga/command/base.rb', line 107

def name
  command_name
end

#output_typeObject



138
139
140
# File 'lib/groonga/command/base.rb', line 138

def output_type
  (self[:output_type] || :json).to_sym
end

#request_idString?

Returns request_id parameter value.

Returns:

  • (String, nil)

    request_id parameter value.

Since:

  • 1.1.8



145
146
147
# File 'lib/groonga/command/base.rb', line 145

def request_id
  self[:request_id]
end

#to_command_format(options = {}) ⇒ Object



153
154
155
156
# File 'lib/groonga/command/base.rb', line 153

def to_command_format(options={})
  format = Format::Command.new(@command_name, normalized_arguments)
  format.command_line(options)
end

#to_elasticsearch_format(options = {}) ⇒ Object



158
159
160
161
# File 'lib/groonga/command/base.rb', line 158

def to_elasticsearch_format(options={})
  format = Format::Elasticsearch.new(self)
  format.json(options)
end

#to_sObject



163
164
165
166
167
168
169
# File 'lib/groonga/command/base.rb', line 163

def to_s
  if uri_format?
    to_uri_format
  else
    to_command_format
  end
end

#to_uri_formatObject



149
150
151
# File 'lib/groonga/command/base.rb', line 149

def to_uri_format
  Format::URI.new(@path_prefix, @command_name, normalized_arguments).path
end

#uri_format?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/groonga/command/base.rb', line 130

def uri_format?
  @original_format == :uri
end