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.



518
519
520
521
522
# File 'lib/groonga/expression-builder.rb', line 518

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)



598
599
600
601
602
603
604
605
606
# File 'lib/groonga/expression-builder.rb', line 598

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



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

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

#call(function, *arguments) ⇒ Object



580
581
582
# File 'lib/groonga/expression-builder.rb', line 580

def call(function, *arguments)
  CallExpressionBuilder.new(@table.context[function], *arguments)
end

#idObject



534
535
536
# File 'lib/groonga/expression-builder.rb', line 534

def id
  self["_id"]
end

#index(name) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
# File 'lib/groonga/expression-builder.rb', line 568

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



538
539
540
# File 'lib/groonga/expression-builder.rb', line 538

def key
  self["_key"]
end

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



550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'lib/groonga/expression-builder.rb', line 550

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



564
565
566
# File 'lib/groonga/expression-builder.rb', line 564

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

#n_sub_recordsObject



546
547
548
# File 'lib/groonga/expression-builder.rb', line 546

def n_sub_records
  self["_nsubrecs"]
end

#scoreObject



542
543
544
# File 'lib/groonga/expression-builder.rb', line 542

def score
  self["_score"]
end