Class: RailsLens::Schema::Adapters::Base
- Inherits:
-
Object
- Object
- RailsLens::Schema::Adapters::Base
- Defined in:
- lib/rails_lens/schema/adapters/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #generate_annotation(_model_class) ⇒ Object
-
#generate_view_annotation(_model_class) ⇒ Object
Default view annotation shared by adapters without dialect-specific view metadata (overridden in PostgreSQL for schema/materialized views).
-
#initialize(connection, table_name) ⇒ Base
constructor
A new instance of Base.
-
#unqualified_table_name ⇒ Object
Extract table name without schema prefix for ActiveRecord connection methods PostgreSQL tables can be schema-qualified (e.g., “cms.posts”).
Constructor Details
#initialize(connection, table_name) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/rails_lens/schema/adapters/base.rb', line 9 def initialize(connection, table_name) @connection = connection @table_name = table_name end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/rails_lens/schema/adapters/base.rb', line 7 def connection @connection end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
7 8 9 |
# File 'lib/rails_lens/schema/adapters/base.rb', line 7 def table_name @table_name end |
Instance Method Details
#generate_annotation(_model_class) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_lens/schema/adapters/base.rb', line 20 def generate_annotation(_model_class) lines = [] lines << "table = \"#{table_name}\"" lines << "database_dialect = \"#{database_dialect}\"" lines << '' add_columns_toml(lines) add_indexes_toml(lines) if show_indexes? add_foreign_keys_toml(lines) if show_foreign_keys? add_check_constraints_toml(lines) if show_check_constraints? lines.join("\n") end |
#generate_view_annotation(_model_class) ⇒ Object
Default view annotation shared by adapters without dialect-specific view metadata (overridden in PostgreSQL for schema/materialized views).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rails_lens/schema/adapters/base.rb', line 36 def generate_view_annotation(_model_class) lines = [] lines << "view = \"#{table_name}\"" lines << "database_dialect = \"#{database_dialect}\"" # Fetch all view metadata in a single query view_info = if view_info lines << "view_type = \"#{view_info[:type]}\"" if view_info[:type] lines << "updatable = #{view_info[:updatable]}" end lines << '' add_columns_toml(lines) add_view_dependencies_toml(lines, view_info) lines.join("\n") end |
#unqualified_table_name ⇒ Object
Extract table name without schema prefix for ActiveRecord connection methods PostgreSQL tables can be schema-qualified (e.g., “cms.posts”)
16 17 18 |
# File 'lib/rails_lens/schema/adapters/base.rb', line 16 def unqualified_table_name @unqualified_table_name ||= table_name.to_s.split('.').last end |