Class: Groonga::RecordExpressionBuilder

Inherits:
Object
  • Object
show all
Includes:
ExpressionBuildable
Defined in:
lib/groonga/expression-builder.rb

Direct Known Subclasses

MatchTargetRecordExpressionBuilder

Constant Summary

Constants included from ExpressionBuildable

ExpressionBuildable::VALID_COLUMN_NAME_RE

Instance Attribute Summary

Attributes included from ExpressionBuildable

#allow_column, #allow_leading_not, #allow_pragma, #allow_update, #default_column, #query, #syntax, #table

Instance Method Summary collapse

Methods included from ExpressionBuildable

#&, #build, #|

Constructor Details

#initialize(table, name) ⇒ RecordExpressionBuilder

Returns a new instance of RecordExpressionBuilder.



444
445
446
447
448
# File 'lib/groonga/expression-builder.rb', line 444

def initialize(table, name)
  super()
  @table = table
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



520
521
522
523
524
525
526
527
528
# File 'lib/groonga/expression-builder.rb', line 520

def method_missing(name, *args, &block)
  return super if block
  return super unless args.empty?
  if VALID_COLUMN_NAME_RE =~ name.to_s
    self[name]
  else
    super
  end
end

Instance Method Details

#[](name) ⇒ Object



450
451
452
453
454
455
456
457
458
# File 'lib/groonga/expression-builder.rb', line 450

def [](name)
  column = @table.column(name)
  if column.nil?
    message = "unknown column <#{name.inspect}> " +
      "for table <#{@table.inspect}>"
    raise ArgumentError, message
  end
  column_expression_builder(column, name)
end

#idObject



460
461
462
# File 'lib/groonga/expression-builder.rb', line 460

def id
  self["_id"]
end

#index(name) ⇒ Object



494
495
496
497
498
499
500
501
502
503
504
# File 'lib/groonga/expression-builder.rb', line 494

def index(name)
  object = @table.context[name]
  if object.nil?
    raise ArgumentError, "unknown index column: <#{name}>"
  end
  if object.range != @table
    raise ArgumentError,
          "different index column: <#{name}>: #{object.inspect}"
  end
  column_expression_builder(object, name)
end

#keyObject



464
465
466
# File 'lib/groonga/expression-builder.rb', line 464

def key
  self["_key"]
end

#match(query, options_or_default_column = {}, &block) ⇒ Object



476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/groonga/expression-builder.rb', line 476

def match(query, options_or_default_column={}, &block)
  if options_or_default_column.is_a?(String)
    options = {:default_column => options_or_default_column}
  else
    options = options_or_default_column
  end
  options = options.dup
  options[:syntax] ||= :query
  if block_given? and options[:default_column].nil?
    options[:default_column] = build_match_target(&block)
  end
  SubExpressionBuilder.new(query, options)
end

#match_target(&block) ⇒ Object



490
491
492
# File 'lib/groonga/expression-builder.rb', line 490

def match_target(&block)
  MatchTargetExpressionBuilder.new(build_match_target(&block))
end

#n_sub_recordsObject



472
473
474
# File 'lib/groonga/expression-builder.rb', line 472

def n_sub_records
  self["_nsubrecs"]
end

#scoreObject



468
469
470
# File 'lib/groonga/expression-builder.rb', line 468

def score
  self["_score"]
end