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.
33 34 35 36 37 |
# File 'lib/viewmatic/schema.rb', line 33 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.
28 29 30 |
# File 'lib/viewmatic/schema.rb', line 28 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.
21 22 23 24 25 |
# File 'lib/viewmatic/schema.rb', line 21 def self.define(&block) schema = new(&block) Viewmatic.schemas << schema schema end |
Instance Method Details
#connection(&block) ⇒ Object
Override the default connection to use.
53 54 55 56 |
# File 'lib/viewmatic/schema.rb', line 53 def connection(&block) @conn_proc = block if block @conn_proc end |
#drop! ⇒ Object
Drop all views defined in this schema.
71 72 73 74 75 76 |
# File 'lib/viewmatic/schema.rb', line 71 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.
61 62 63 64 65 66 |
# File 'lib/viewmatic/schema.rb', line 61 def load! conn = @conn_proc.call views.each do |_name, view| conn.execute SchemaStatements.create_view view end end |
#view(name) {|view| ... } ⇒ Object
Define a new view.
44 45 46 47 48 |
# File 'lib/viewmatic/schema.rb', line 44 def view(name) view = views[name] = View.new(name) yield view if block_given? view end |