Class: Groonga::Schema::ViewDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/schema.rb

Overview

スキーマ定義時に create_view#create_view からブロックに渡されてくる オブジェクト

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ ViewDefinition

Returns a new instance of ViewDefinition.



1602
1603
1604
1605
1606
1607
1608
# File 'lib/groonga/schema.rb', line 1602

def initialize(name, options)
  @name = name
  @name = @name.to_s if @name.is_a?(Symbol)
  @tables = []
  validate_options(options)
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

ビューの名前



1599
1600
1601
# File 'lib/groonga/schema.rb', line 1599

def name
  @name
end

Instance Method Details

#add(table) ⇒ Object

名前が table のテーブルをビューに追加する。



1634
1635
1636
1637
1638
# File 'lib/groonga/schema.rb', line 1634

def add(table)
  table = table.to_s if table.is_a?(Symbol)
  @tables << table
  self
end

#contextObject



1641
1642
1643
# File 'lib/groonga/schema.rb', line 1641

def context
  @options[:context] || Groonga::Context.default
end

#defineObject



1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
# File 'lib/groonga/schema.rb', line 1611

def define
  view = context[@name]
  if @options[:change]
    raise TableNotExists.new(@name) if view.nil?
  else
    if view and @options[:force]
      view.remove
      view = nil
    end
    view ||= Groonga::View.create(create_options)
  end
  @tables.each do |table|
    unless table.is_a?(Groonga::Table)
      table_name = table
      table = context[table_name]
      raise TableNotExists.new(table_name) if table.nil?
    end
    view.add_table(table)
  end
  view
end