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.



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

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.



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

def arguments
  @arguments
end

#command_nameString (readonly)

Returns The command name.

Returns:

  • (String)

    The command name.

Since:

  • 1.1.8



57
58
59
# File 'lib/groonga/command/base.rb', line 57

def command_name
  @command_name
end

#original_formatObject

Returns the value of attribute original_format.



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

def original_format
  @original_format
end

#original_sourceObject

Returns the value of attribute original_source.



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

def original_source
  @original_source
end

#path_prefixObject

Returns the value of attribute path_prefix.



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

def path_prefix
  @path_prefix
end

Class Method Details

.parameter_namesObject



49
50
51
# File 'lib/groonga/command/base.rb', line 49

def parameter_names
  []
end

Instance Method Details

#==(other) ⇒ Object



122
123
124
125
126
# File 'lib/groonga/command/base.rb', line 122

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

#[](name) ⇒ Object



109
110
111
# File 'lib/groonga/command/base.rb', line 109

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

#[]=(name, value) ⇒ Object



113
114
115
# File 'lib/groonga/command/base.rb', line 113

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

#command_format?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/groonga/command/base.rb', line 132

def command_format?
  @original_format == :command
end

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

Returns:

  • (Boolean)


117
118
119
# File 'lib/groonga/command/base.rb', line 117

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

#nameObject

Deprecated.

since 1.1.8. Use #command_name instead.



105
106
107
# File 'lib/groonga/command/base.rb', line 105

def name
  command_name
end

#output_typeObject



136
137
138
# File 'lib/groonga/command/base.rb', line 136

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



143
144
145
# File 'lib/groonga/command/base.rb', line 143

def request_id
  self[:request_id]
end

#to_command_formatObject



151
152
153
# File 'lib/groonga/command/base.rb', line 151

def to_command_format
  Format::Command.new(@command_name, normalized_arguments).command_line
end

#to_uri_formatObject



147
148
149
# File 'lib/groonga/command/base.rb', line 147

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

#uri_format?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/groonga/command/base.rb', line 128

def uri_format?
  @original_format == :uri
end