Class: RailsLens::ViewMetadata
- Inherits:
-
Object
- Object
- RailsLens::ViewMetadata
- Defined in:
- lib/rails_lens/view_metadata.rb
Overview
Extracts and manages metadata for database views and materialized views
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#initialize(model_class) ⇒ ViewMetadata
constructor
A new instance of ViewMetadata.
- #last_refreshed ⇒ Object
- #materialized_view? ⇒ Boolean
- #refresh_strategy ⇒ Object
- #regular_view? ⇒ Boolean
- #to_h ⇒ Object
- #updatable? ⇒ Boolean
- #view_definition ⇒ Object
- #view_exists? ⇒ Boolean
- #view_type ⇒ Object
Constructor Details
#initialize(model_class) ⇒ ViewMetadata
Returns a new instance of ViewMetadata.
8 9 10 11 12 13 14 |
# File 'lib/rails_lens/view_metadata.rb', line 8 def initialize(model_class) @model_class = model_class @connection = model_class.connection @table_name = model_class.table_name @adapter_name = connection.adapter_name.downcase @adapter = create_adapter end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/rails_lens/view_metadata.rb', line 6 def connection @connection end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
6 7 8 |
# File 'lib/rails_lens/view_metadata.rb', line 6 def model_class @model_class end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/rails_lens/view_metadata.rb', line 6 def table_name @table_name end |
Instance Method Details
#dependencies ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rails_lens/view_metadata.rb', line 42 def dependencies return [] unless view_exists? @adapter&.view_dependencies || [] rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotDefined [] end |
#last_refreshed ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rails_lens/view_metadata.rb', line 56 def last_refreshed return nil unless materialized_view? @adapter&.view_last_refreshed rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotDefined nil end |
#materialized_view? ⇒ Boolean
26 27 28 |
# File 'lib/rails_lens/view_metadata.rb', line 26 def materialized_view? view_type == 'materialized' end |
#refresh_strategy ⇒ Object
50 51 52 53 54 |
# File 'lib/rails_lens/view_metadata.rb', line 50 def refresh_strategy return nil unless materialized_view? @adapter&.view_refresh_strategy end |
#regular_view? ⇒ Boolean
30 31 32 |
# File 'lib/rails_lens/view_metadata.rb', line 30 def regular_view? view_type == 'regular' end |
#to_h ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rails_lens/view_metadata.rb', line 72 def to_h { view_type: view_type, updatable: updatable?, dependencies: dependencies, refresh_strategy: refresh_strategy, last_refreshed: last_refreshed, view_definition: view_definition }.compact end |
#updatable? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/rails_lens/view_metadata.rb', line 34 def updatable? return false unless view_exists? @adapter&.view_updatable? || false rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotDefined false end |
#view_definition ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/rails_lens/view_metadata.rb', line 64 def view_definition return nil unless view_exists? @adapter&.view_definition rescue ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotDefined nil end |
#view_exists? ⇒ Boolean
22 23 24 |
# File 'lib/rails_lens/view_metadata.rb', line 22 def view_exists? ModelDetector.view_exists?(model_class) end |
#view_type ⇒ Object
16 17 18 19 20 |
# File 'lib/rails_lens/view_metadata.rb', line 16 def view_type return nil unless view_exists? @adapter&.view_type end |