class Viewmatic::Schema
Represents a schema of views to be built.
Attributes
paths[R]
@return [Array<String>] Array of globs matching view definition files. default: ['db/views.rb', 'db/views/*.rb']
views[R]
@return [Array<Viewmatic::View] all defined views in this schema
Public Class Methods
define(&block)
click to toggle source
Define a new schema. If you pass a block, it will be eval'd inside the Schema
instance.
@return [Viewmatic::Schema]
# File lib/viewmatic/schema.rb, line 26 def self.define(&block) schema = new(&block) Viewmatic.schemas << schema schema end
new(&block)
click to toggle source
Initialize a new schema. If you pass a block it will be eval'd inside the instance.
# File lib/viewmatic/schema.rb, line 38 def initialize(&block) @views = {} @conn_proc = -> { ActiveRecord::Base.connection } instance_exec(&block) if block end
Public Instance Methods
connection(&block)
click to toggle source
Override the default connection to use.
# File lib/viewmatic/schema.rb, line 58 def connection(&block) @conn_proc = block if block @conn_proc end
drop!()
click to toggle source
Drop all views defined in this schema.
# 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!()
click to toggle source
Create all views defined in this schema.
# 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
view(name) { |view| ... }
click to toggle source
Define a new view.
@param name [Symbol] what to call the view
# File lib/viewmatic/schema.rb, line 49 def view(name) view = views[name] = View.new(name) yield view if block_given? view end