module Cell::Meta
Constants
- GLOBAL_KEY
Public Class Methods
add_global_table(name)
click to toggle source
# File lib/cell/meta.rb, line 72 def self.add_global_table(name) set_global_tables(global_tables + [name.to_s]) end
connection()
click to toggle source
# File lib/cell/meta.rb, line 8 def self.connection ::ActiveRecord::Base.connection end
global_model?(m)
click to toggle source
# File lib/cell/meta.rb, line 80 def self.global_model?(m) @model_map ||= global_tables.map do |k| [k, true] end.to_h @model_map[m.table_name] || false end
global_schema()
click to toggle source
# File lib/cell/meta.rb, line 34 def self.global_schema # This could be racy? @global_schema ||= ::ActiveRecord::Base.connection.schema_search_path end
global_tables()
click to toggle source
# File lib/cell/meta.rb, line 59 def self.global_tables with_global_schema do (::ActiveRecord::InternalMetadata[GLOBAL_KEY] || '').split(',') end end
prototype_schema()
click to toggle source
# File lib/cell/meta.rb, line 39 def self.prototype_schema 'cell_prototype' end
remove_global_table(name)
click to toggle source
# File lib/cell/meta.rb, line 76 def self.remove_global_table(name) set_global_tables(global_tables - [name.to_s]) end
set_global_tables(tables)
click to toggle source
# File lib/cell/meta.rb, line 65 def self.set_global_tables(tables) with_global_schema do table_string = tables.map(&:to_s).sort.uniq.join(',') ::ActiveRecord::InternalMetadata[GLOBAL_KEY] = table_string end end
set_schema_search_path(path)
click to toggle source
# File lib/cell/meta.rb, line 27 def self.set_schema_search_path(path) if path != connection.schema_search_path connection.schema_search_path = path connection.clear_query_cache end end
structural_schema()
click to toggle source
# File lib/cell/meta.rb, line 43 def self.structural_schema "#{prototype_schema},#{global_schema}" end
with_global_schema(&block)
click to toggle source
# File lib/cell/meta.rb, line 47 def self.with_global_schema(&block) with_schema(global_schema, exclusive: true, &block) end
with_prototype_schema(&block)
click to toggle source
# File lib/cell/meta.rb, line 51 def self.with_prototype_schema(&block) with_schema(prototype_schema, exclusive: true, &block) end
with_schema(new_path, exclusive: false) { || ... }
click to toggle source
# File lib/cell/meta.rb, line 12 def self.with_schema(new_path, exclusive: false) saved_path = connection.schema_search_path active_path = exclusive ? new_path : "#{new_path},#{saved_path}" set_schema_search_path(active_path) if block_given? begin yield ensure set_schema_search_path(saved_path) end end end
with_structural_schema(&block)
click to toggle source
# File lib/cell/meta.rb, line 55 def self.with_structural_schema(&block) with_schema(structural_schema, exclusive: true, &block) end