Class: Groonga::Schema::ViewDefinition

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ ViewDefinition

Returns a new instance of ViewDefinition.



1660
1661
1662
1663
1664
1665
1666
# File 'lib/groonga/schema.rb', line 1660

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)

ビューの名前



1657
1658
1659
# File 'lib/groonga/schema.rb', line 1657

def name
  @name
end

Instance Method Details

#add(table) ⇒ Object

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



1692
1693
1694
1695
1696
# File 'lib/groonga/schema.rb', line 1692

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

#contextObject



1699
1700
1701
# File 'lib/groonga/schema.rb', line 1699

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

#defineObject



1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
# File 'lib/groonga/schema.rb', line 1669

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