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.



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

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)



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

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



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

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



462
463
464
# File 'lib/groonga/expression-builder.rb', line 462

def id
  self["_id"]
end

#index(name) ⇒ Object



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

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



466
467
468
# File 'lib/groonga/expression-builder.rb', line 466

def key
  self["_key"]
end

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



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

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



492
493
494
# File 'lib/groonga/expression-builder.rb', line 492

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

#n_sub_recordsObject



474
475
476
# File 'lib/groonga/expression-builder.rb', line 474

def n_sub_records
  self["_nsubrecs"]
end

#scoreObject



470
471
472
# File 'lib/groonga/expression-builder.rb', line 470

def score
  self["_score"]
end