Class: EmptyEye::ViewManager

Inherits:
ActiveRecord::Base show all
Defined in:
lib/empty_eye/view_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseMethods

included, #valid?

Methods included from Relation

included

Methods included from Persistence

#create, #delete, #destroy, #update

Instance Attribute Details

#sqlObject

Returns the value of attribute sql.



5
6
7
# File 'lib/empty_eye/view_manager.rb', line 5

def sql
  @sql
end

Class Method Details

.create_view(view_name, sql) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/empty_eye/view_manager.rb', line 7

def self.create_view(view_name, sql)
  if table_exists?
    manager = find_by_view_name(view_name) 
    manager ||= new(:view_name => view_name)
    manager.sql = sql
    manager.create_view
  else
    drop_view(view_name)
    execute_view(sql)
  end
end

.drop_view(view_name) ⇒ Object



23
24
25
# File 'lib/empty_eye/view_manager.rb', line 23

def self.drop_view(view_name)
  connection.execute %{DROP VIEW #{view_name}} rescue nil
end

.execute_view(sql) ⇒ Object



19
20
21
# File 'lib/empty_eye/view_manager.rb', line 19

def self.execute_view(sql)
  connection.execute(sql)
end

Instance Method Details

#create_viewObject



27
28
29
30
31
32
33
# File 'lib/empty_eye/view_manager.rb', line 27

def create_view
  return unless create_view? 
  drop_view if view_exists?
  self.version = compute_version
  save
  execute_view_sql
end