Class: ActiveRecord::DatabaseViews::View
- Inherits:
-
Object
- Object
- ActiveRecord::DatabaseViews::View
- Defined in:
- lib/activerecord-database-views/view.rb
Constant Summary collapse
- FILE_NAME_MATCHER_WITH_PREFIX =
/^\d+?_(.+)/
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #drop! ⇒ Object
-
#initialize(path) ⇒ View
constructor
A new instance of View.
- #load! ⇒ Object
- #name ⇒ Object
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
#path ⇒ Object (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 |
#name ⇒ Object
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 |