Module: Groonga::QueryLogger::Flags

Defined in:
lib/groonga/query-logger.rb

Constant Summary collapse

NAMES =
{
  :none        => NONE,
  :command     => COMMAND,
  :result_code => RESULT_CODE,
  :destination => DESTINATION,
  :cache       => CACHE,
  :size        => SIZE,
  :score       => SCORE,
}
LABELS =
{
  NONE        => "none",
  COMMAND     => "command",
  RESULT_CODE => "result_code",
  DESTINATION => "destination",
  CACHE       => "cache",
  SIZE        => "size",
  SCORE       => "score",
}

Class Method Summary collapse

Class Method Details

.label(flags) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/groonga/query-logger.rb', line 81

def label(flags)
  labels = []
  LABELS.each do |flag, label|
    flags << label if (flags & flag) == flag
  end
  labels << "none" if labels.empty?
  labels.join("|")
end

.parse(input, base_flags = nil) ⇒ Object

TODO: Document me.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/groonga/query-logger.rb', line 43

def parse(input, base_flags=nil)
  base_flags ||= Flags::NONE
  case input
  when nil
    base_flags
  when Integer
    input | base_flags
  when String, Symbol
    value = NAMES[input.to_sym]
    if value.nil?
      message =
        "flag name must be one of #{NAMES.keys.inspect}: " +
        "<#{input.inspect}>"
      raise ArgumentError, message
    end
    value | base_flags
  when ::Array
    input.inject(base_flags) do |flags, sub_input|
      parse(sub_input, flags)
    end
  when ::Hash
    flags = base_flags
    input.each do |key, use_key|
      if use_key
        flags = parse(key, flags)
      else
        flags &= ~parse(key, 0)
      end
    end
    flags
  else
    message =
      "flags value must be nil, Integer, names, " +
      "Array of flag or Hash of name and boolean: <#{input.inspect}>"
    raise ArgumentError, message
  end
end