Module: NoBrainer::Document::TableConfig::ClassMethods
- Defined in:
- lib/no_brainer/document/table_config.rb
Instance Method Summary collapse
- #_set_table_config(options) ⇒ Object
- #rebalance ⇒ Object
- #rql_table ⇒ Object
- #store_in(options) ⇒ Object
- #sync_indexes(options = {}) ⇒ Object
- #sync_schema(options = {}) ⇒ Object
- #sync_table_config(options = {}) ⇒ Object
- #table_config(options = {}) ⇒ Object
- #table_create_options ⇒ Object
- #table_name ⇒ Object
- #table_stats ⇒ Object
- #table_status ⇒ Object
- #table_wait ⇒ Object
Instance Method Details
#_set_table_config(options) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/no_brainer/document/table_config.rb', line 30 def _set_table_config() raise "table_config() must be used at the parent class, not a subclass" unless is_root_class? .assert_valid_keys(*VALID_TABLE_CONFIG_OPTIONS) self..merge!() end |
#rebalance ⇒ Object
60 61 62 63 |
# File 'lib/no_brainer/document/table_config.rb', line 60 def rebalance NoBrainer.run { rql_table.rebalance } true end |
#rql_table ⇒ Object
43 44 45 |
# File 'lib/no_brainer/document/table_config.rb', line 43 def rql_table RethinkDB::RQL.new.table(table_name) end |
#store_in(options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/no_brainer/document/table_config.rb', line 17 def store_in() if [:table] STDERR.puts "[NoBrainer] `store_in(table: ...)' has been removed. Use `table_config(name: ...)' instead." [:name] = .delete(:table) end if [:database] || [:db] raise "`store_in(db: ...)' has been removed. Use `run_with(db: ...)' instead." end table_config() end |
#sync_indexes(options = {}) ⇒ Object
85 86 87 |
# File 'lib/no_brainer/document/table_config.rb', line 85 def sync_indexes(={}) NoBrainer::Document::Index::Synchronizer.new(self).sync_indexes() end |
#sync_schema(options = {}) ⇒ Object
89 90 91 92 |
# File 'lib/no_brainer/document/table_config.rb', line 89 def sync_schema(={}) sync_table_config() sync_indexes() end |
#sync_table_config(options = {}) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/no_brainer/document/table_config.rb', line 78 def sync_table_config(={}) c = 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 = {}) ⇒ Object
47 48 49 50 |
# File 'lib/no_brainer/document/table_config.rb', line 47 def table_config(={}) return _set_table_config() unless .empty? NoBrainer::System::TableConfig.new_from_db(NoBrainer.run { rql_table.config }) end |
#table_create_options ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/no_brainer/document/table_config.rb', line 69 def NoBrainer::Config. .merge() .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 ⇒ Object
37 38 39 40 41 |
# File 'lib/no_brainer/document/table_config.rb', line 37 def table_name name = [:name] name = name.call if name.is_a?(Proc) (name || root_class.name.tableize.gsub('/', '__')).to_s end |
#table_stats ⇒ Object
56 57 58 |
# 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 ⇒ Object
52 53 54 |
# 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 ⇒ Object
65 66 67 |
# File 'lib/no_brainer/document/table_config.rb', line 65 def table_wait NoBrainer.run { rql_table.wait } end |