module NoBrainer::Document::TableConfig::ClassMethods

Public Instance Methods

_set_table_config(options) click to toggle source
# File lib/no_brainer/document/table_config.rb, line 30
def _set_table_config(options)
  raise "table_config() must be used at the parent class, not a subclass" unless is_root_class?

  options.assert_valid_keys(*VALID_TABLE_CONFIG_OPTIONS)
  self.table_config_options.merge!(options)
end
rebalance() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 60
def rebalance
  NoBrainer.run { rql_table.rebalance }
  true
end
rql_table() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 43
def rql_table
  RethinkDB::RQL.new.table(table_name)
end
store_in(options) click to toggle source
# File lib/no_brainer/document/table_config.rb, line 17
def store_in(options)
  if options[:table]
    STDERR.puts "[NoBrainer] `store_in(table: ...)' has been removed. Use `table_config(name: ...)' instead."
    options[:name] = options.delete(:table)
  end

  if options[:database] || options[:db]
    raise "`store_in(db: ...)' has been removed. Use `run_with(db: ...)' instead."
  end

  table_config(options)
end
sync_indexes(options={}) click to toggle source
# File lib/no_brainer/document/table_config.rb, line 85
def sync_indexes(options={})
  NoBrainer::Document::Index::Synchronizer.new(self).sync_indexes(options)
end
sync_schema(options={}) click to toggle source
# File lib/no_brainer/document/table_config.rb, line 89
def sync_schema(options={})
  sync_table_config(options)
  sync_indexes(options)
end
sync_table_config(options={}) click to toggle source
# File lib/no_brainer/document/table_config.rb, line 78
def sync_table_config(options={})
  c = table_create_options
  table_config.update!(c.slice(:durability, :primary_key, :write_acks))
  NoBrainer.run { rql_table.reconfigure(c.slice(:shards, :replicas, :primary_replica_tag, :nonvoting_replica_tags)) }
  true
end
table_config(options={}) click to toggle source
# File lib/no_brainer/document/table_config.rb, line 47
def table_config(options={})
  return _set_table_config(options) unless options.empty?
  NoBrainer::System::TableConfig.new_from_db(NoBrainer.run { rql_table.config })
end
table_create_options() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 69
def table_create_options
  NoBrainer::Config.table_options
    .merge(table_config_options)
    .merge(:name => table_name)
    .merge(:primary_key => lookup_field_alias(pk_name))
    .reverse_merge(:durability => 'hard')
    .reduce({}) { |h,(k,v)| h[k] = v.is_a?(Symbol) ? v.to_s : v; h } # symbols -> strings
end
table_name() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 37
def table_name
  name = table_config_options[:name]
  name = name.call if name.is_a?(Proc)
  (name || root_class.name.tableize.gsub('/', '__')).to_s
end
table_stats() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 56
def table_stats
  NoBrainer::System::Stats.where(:db => NoBrainer.current_db, :table => table_name).to_a
end
table_status() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 52
def table_status
  NoBrainer::System::TableConfig.new_from_db(NoBrainer.run { rql_table.status })
end
table_wait() click to toggle source
# File lib/no_brainer/document/table_config.rb, line 65
def table_wait
  NoBrainer.run { rql_table.wait }
end