Class: Viewmatic::Schema
- Inherits:
-
Object
- Object
- Viewmatic::Schema
- Defined in:
- lib/viewmatic/schema.rb
Overview
Represents a schema of views to be built.
Class Attribute Summary collapse
-
.paths ⇒ Array<String>
readonly
Array of globs matching view definition files.
Instance Attribute Summary collapse
-
#views ⇒ Array<Viewmatic::View] all defined views in this schema
readonly
Array<Viewmatic::View] all defined views in this schema.
Class Method Summary collapse
-
.define(&block) ⇒ Viewmatic::Schema
Define a new schema.
Instance Method Summary collapse
-
#connection(&block) ⇒ Object
Override the default connection to use.
-
#drop! ⇒ Object
Drop all views defined in this schema.
-
#initialize(&block) ⇒ Schema
constructor
Initialize a new schema.
-
#load! ⇒ Object
Create all views defined in this schema.
-
#view(name) {|view| ... } ⇒ Object
Define a new view.
Constructor Details
#initialize(&block) ⇒ Schema
Initialize a new schema. If you pass a block it will be eval’d inside the instance.
38 39 40 41 42 |
# File 'lib/viewmatic/schema.rb', line 38 def initialize(&block) @views = {} @conn_proc = -> { ActiveRecord::Base.connection } instance_exec(&block) if block end |
Class Attribute Details
.paths ⇒ Array<String> (readonly)
Returns Array of globs matching view definition files. default: [‘db/views.rb’, ‘db/views/*.rb’].
8 9 10 |
# File 'lib/viewmatic/schema.rb', line 8 def paths @paths end |
Instance Attribute Details
#views ⇒ Array<Viewmatic::View] all defined views in this schema (readonly)
Returns Array<Viewmatic::View] all defined views in this schema.
33 34 35 |
# File 'lib/viewmatic/schema.rb', line 33 def views @views end |
Class Method Details
.define(&block) ⇒ Viewmatic::Schema
Define a new schema. If you pass a block, it will be eval’d inside the Schema instance.
26 27 28 29 30 |
# File 'lib/viewmatic/schema.rb', line 26 def self.define(&block) schema = new(&block) Viewmatic.schemas << schema schema end |
Instance Method Details
#connection(&block) ⇒ Object
Override the default connection to use.
58 59 60 61 |
# File 'lib/viewmatic/schema.rb', line 58 def connection(&block) @conn_proc = block if block @conn_proc end |
#drop! ⇒ Object
Drop all views defined in this schema.
76 77 78 79 80 81 |
# File 'lib/viewmatic/schema.rb', line 76 def drop! conn = @conn_proc.call views.each do |_name, view| conn.execute SchemaStatements.drop_view view end end |
#load! ⇒ Object
Create all views defined in this schema.
66 67 68 69 70 71 |
# File 'lib/viewmatic/schema.rb', line 66 def load! conn = @conn_proc.call views.each do |_name, view| conn.execute SchemaStatements.create_view view end end |