Module: Models::DatabaseView::ClassMethods
- Defined in:
- app/concerns/models/database_view.rb
Overview
ActiveSupport::Concern mixin: class methods.
Instance Method Summary collapse
- #drop_view ⇒ Object
- #get_view_sql ⇒ Object
- #install_view ⇒ Object
- #reset ⇒ Object
- #table_name ⇒ Object
Instance Method Details
#drop_view ⇒ Object
15 16 17 |
# File 'app/concerns/models/database_view.rb', line 15 def drop_view connection.execute("DROP VIEW IF EXISTS #{table_name};") end |
#get_view_sql ⇒ Object
33 34 35 36 |
# File 'app/concerns/models/database_view.rb', line 33 def get_view_sql view_sql_path = Rails.root.join('data', 'views', "#{name.tableize}.sql") IO.read(view_sql_path) end |
#install_view ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/concerns/models/database_view.rb', line 19 def install_view connection.execute <<-EOS CREATE VIEW #{table_name} AS #{get_view_sql} EOS reset_column_information end |
#reset ⇒ Object
27 28 29 30 31 |
# File 'app/concerns/models/database_view.rb', line 27 def reset drop_view install_view true end |
#table_name ⇒ Object
11 12 13 |
# File 'app/concerns/models/database_view.rb', line 11 def table_name name.tableize.tr('/', '_') end |