Class: ActiveRecord::DatabaseViews::View

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-database-views/view.rb

Constant Summary collapse

FILE_NAME_MATCHER_WITH_PREFIX =
/^\d+?_(.+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ View

Returns a new instance of View.



7
8
9
# File 'lib/activerecord-database-views/view.rb', line 7

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/activerecord-database-views/view.rb', line 5

def path
  @path
end

Instance Method Details

#drop!Object



11
12
13
# File 'lib/activerecord-database-views/view.rb', line 11

def drop!
  call_sql!("DROP VIEW IF EXISTS #{name} CASCADE;")
end

#load!Object



15
16
17
# File 'lib/activerecord-database-views/view.rb', line 15

def load!
  call_sql!("CREATE OR REPLACE VIEW #{name} AS #{sql};")
end

#nameObject



19
20
21
22
23
24
25
# File 'lib/activerecord-database-views/view.rb', line 19

def name
  if basename =~ FILE_NAME_MATCHER_WITH_PREFIX
    FILE_NAME_MATCHER_WITH_PREFIX.match(basename)[1]
  else
    basename
  end
end