Module: Models::DatabaseView::ClassMethods
- Defined in:
- app/concerns/models/database_view.rb
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
13 14 15 |
# File 'app/concerns/models/database_view.rb', line 13 def drop_view connection.execute("DROP VIEW IF EXISTS #{table_name};") end |
#get_view_sql ⇒ Object
31 32 33 34 |
# File 'app/concerns/models/database_view.rb', line 31 def get_view_sql view_sql_path = Rails.root.join('data', 'views', "#{name.tableize}.sql") IO.read(view_sql_path) end |
#install_view ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/concerns/models/database_view.rb', line 17 def install_view connection.execute <<-EOS CREATE VIEW #{table_name} AS #{get_view_sql} EOS reset_column_information end |
#reset ⇒ Object
25 26 27 28 29 |
# File 'app/concerns/models/database_view.rb', line 25 def reset drop_view install_view true end |
#table_name ⇒ Object
9 10 11 |
# File 'app/concerns/models/database_view.rb', line 9 def table_name name.tableize.tr('/', '_') end |