Module: Views

Defined in:
lib/views.rb,
lib/views/version.rb,
lib/generators/views/view_generator.rb

Defined Under Namespace

Modules: Generators

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.syncObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/views.rb', line 4

def sync
  pattern = Rails.root.join('db/views/*.sql')
  Dir.glob(pattern) do |path|
    path = Pathname.new(path)
    if changed?(path)
      name = path.basename('.sql')
      sql = File.read(path)
      puts "Updating #{name}"
      connection.execute "DROP VIEW IF EXISTS #{name}"
      connection.execute "CREATE VIEW #{name} AS \n #{sql}"
    end
  end
end