Module: Torque::PostgreSQL::SchemaCache
- Includes:
- Inheritance
- Defined in:
- lib/torque/postgresql/schema_cache.rb,
lib/torque/postgresql/schema_cache/inheritance.rb
Overview
:TODO: Create the add
to load inheritance info
Defined Under Namespace
Modules: Inheritance
Instance Method Summary collapse
-
#add(connection_or_table_name, table_name = connection_or_table_name) ⇒ Object
:nodoc:.
-
#add_model_name(*args) ⇒ Object
A way to manually add models name so it doesn’t need the lookup method.
-
#associations(source, table_name = source) ⇒ Object
Get the list of all tables that are associated (direct or indirect inheritance) with the provided one.
-
#clear! ⇒ Object
:nodoc:.
-
#clear_data_source_cache!(connection_or_name, name = connection_or_name) ⇒ Object
:nodoc:.
-
#dependencies(source, table_name = source) ⇒ Object
Get all the tables that the given one inherits from.
-
#encode_with(coder) ⇒ Object
:nodoc:.
-
#init_with(coder) ⇒ Object
:nodoc:.
-
#initialize ⇒ Object
:nodoc:.
-
#initialize_dup ⇒ Object
:nodoc:.
-
#lookup_model(*args, **xargs) ⇒ Object
Override the inheritance implementation to pass over the proper cache of the existing association between data sources and model names.
-
#marshal_dump ⇒ Object
:nodoc:.
-
#marshal_load(array) ⇒ Object
:nodoc:.
-
#size ⇒ Object
:nodoc:.
Instance Method Details
#add(connection_or_table_name, table_name = connection_or_table_name) ⇒ Object
:nodoc:
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/torque/postgresql/schema_cache.rb', line 48 def add(connection_or_table_name, table_name = connection_or_table_name, *) # :nodoc: super # Reset inheritance information when a table is added if @data_sources.key?(table_name) @inheritance_dependencies.clear @inheritance_associations.clear @inheritance_loaded = false end end |
#add_model_name(*args) ⇒ Object
A way to manually add models name so it doesn’t need the lookup method
100 101 102 103 104 105 |
# File 'lib/torque/postgresql/schema_cache.rb', line 100 def add_model_name(*args) model, *source = args.reverse return unless data_source_exists?(*source.reverse) && model.is_a?(Class) @data_sources_model_names[source.first] = model end |
#associations(source, table_name = source) ⇒ Object
Get the list of all tables that are associated (direct or indirect inheritance) with the provided one
115 116 117 118 |
# File 'lib/torque/postgresql/schema_cache.rb', line 115 def associations(source, table_name = source) reload_inheritance_data!(source == table_name ? connection : source) @inheritance_associations[table_name] end |
#clear! ⇒ Object
:nodoc:
59 60 61 62 63 64 65 |
# File 'lib/torque/postgresql/schema_cache.rb', line 59 def clear! # :nodoc: super @data_sources_model_names.clear @inheritance_dependencies.clear @inheritance_associations.clear @inheritance_loaded = false end |
#clear_data_source_cache!(connection_or_name, name = connection_or_name) ⇒ Object
:nodoc:
75 76 77 78 79 80 |
# File 'lib/torque/postgresql/schema_cache.rb', line 75 def clear_data_source_cache!(connection_or_name, name = connection_or_name) # :nodoc: Torque::PostgreSQL::AR710 ? super : super(name) @data_sources_model_names.delete name @inheritance_dependencies.delete name @inheritance_associations.delete name end |
#dependencies(source, table_name = source) ⇒ Object
Get all the tables that the given one inherits from
108 109 110 111 |
# File 'lib/torque/postgresql/schema_cache.rb', line 108 def dependencies(source, table_name = source) reload_inheritance_data!(source == table_name ? connection : source) @inheritance_dependencies[table_name] end |
#encode_with(coder) ⇒ Object
:nodoc:
34 35 36 37 38 39 |
# File 'lib/torque/postgresql/schema_cache.rb', line 34 def encode_with(coder) # :nodoc: super coder['data_sources_model_names'] = @data_sources_model_names coder['inheritance_dependencies'] = @inheritance_dependencies coder['inheritance_associations'] = @inheritance_associations end |
#init_with(coder) ⇒ Object
:nodoc:
41 42 43 44 45 46 |
# File 'lib/torque/postgresql/schema_cache.rb', line 41 def init_with(coder) # :nodoc: super @data_sources_model_names = coder['data_sources_model_names'] @inheritance_dependencies = coder['inheritance_dependencies'] @inheritance_associations = coder['inheritance_associations'] end |
#initialize ⇒ Object
:nodoc:
18 19 20 21 22 23 24 25 |
# File 'lib/torque/postgresql/schema_cache.rb', line 18 def initialize(*) # :nodoc: super @data_sources_model_names = {} @inheritance_dependencies = {} @inheritance_associations = {} @inheritance_loaded = false end |
#initialize_dup ⇒ Object
:nodoc:
27 28 29 30 31 32 |
# File 'lib/torque/postgresql/schema_cache.rb', line 27 def initialize_dup(*) # :nodoc: super @data_sources_model_names = @data_sources_model_names.dup @inheritance_dependencies = @inheritance_dependencies.dup @inheritance_associations = @inheritance_associations.dup end |
#lookup_model(*args, **xargs) ⇒ Object
Override the inheritance implementation to pass over the proper cache of the existing association between data sources and model names
122 123 124 |
# File 'lib/torque/postgresql/schema_cache.rb', line 122 def lookup_model(*args, **xargs) super(*args, **xargs, source_to_model: @data_sources_model_names) end |
#marshal_dump ⇒ Object
:nodoc:
82 83 84 85 86 87 88 89 |
# File 'lib/torque/postgresql/schema_cache.rb', line 82 def marshal_dump # :nodoc: super + [ @inheritance_dependencies, @inheritance_associations, @data_sources_model_names, @inheritance_loaded, ] end |
#marshal_load(array) ⇒ Object
:nodoc:
91 92 93 94 95 96 97 |
# File 'lib/torque/postgresql/schema_cache.rb', line 91 def marshal_load(array) # :nodoc: @inheritance_loaded = array.pop @data_sources_model_names = array.pop @inheritance_associations = array.pop @inheritance_dependencies = array.pop super end |
#size ⇒ Object
:nodoc:
67 68 69 70 71 72 73 |
# File 'lib/torque/postgresql/schema_cache.rb', line 67 def size # :nodoc: super + [ @data_sources_model_names, @inheritance_dependencies, @inheritance_associations, ].map(&:size).inject(:+) end |