Module: Views::Extensions::ActiveRecord::PostgreSQLAdapter

Extended by:
ActiveSupport::Concern
Defined in:
lib/views/extensions/active_record/postgresql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#change_view(name, options = {}) ⇒ Object



16
17
18
19
# File 'lib/views/extensions/active_record/postgresql_adapter.rb', line 16

def change_view(name, options={})
  drop_view name
  create_view name, options
end

#create_view(name, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/views/extensions/active_record/postgresql_adapter.rb', line 7

def create_view(name, options={})
  if options[:force]
    execute "DROP VIEW IF EXISTS #{name}"
  end
  path = Rails.root.join("db/views/#{name}.sql")
  definition = File.read(path)
  execute "CREATE VIEW #{name} AS #{definition}"
end

#drop_view(name) ⇒ Object



21
22
23
# File 'lib/views/extensions/active_record/postgresql_adapter.rb', line 21

def drop_view(name)
  execute "DROP VIEW #{name}"
end

#viewsObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/views/extensions/active_record/postgresql_adapter.rb', line 25

def views
  execute "    SELECT c.relname as name, c.relkind AS type\n    FROM pg_class c\n    LEFT JOIN pg_namespace n ON n.oid = c.relnamespace\n    WHERE c.relkind IN ('v')\n    AND n.nspname = ANY (current_schemas(false))\n    ORDER BY c.oid ASC\n  SQL\nend\n"