module Monocle

An in-memory representation of the view

Constants

VERSION

Public Class Methods

bump(view_name) click to toggle source
# File lib/monocle.rb, line 47
def bump(view_name)
  BumpCommand.new(fetch(view_name)).call
end
configure() { |configuration| ... } click to toggle source

Enables you to configure things in a block, i.e Monocle.configure do |config|

config.logger = MyLogger.new
config.path_to_views = "my/different/path/to/my/sql/files"

end

# File lib/monocle.rb, line 71
def configure
  yield configuration if block_given?
end
create(view_name) click to toggle source
# File lib/monocle.rb, line 30
def create(view_name)
  fetch(view_name).create
end
drop(view_name) click to toggle source
# File lib/monocle.rb, line 26
def drop(view_name)
  fetch(view_name).drop
end
fetch(view_name) click to toggle source
# File lib/monocle.rb, line 89
def fetch(view_name)
  view_name = symbolize_name(view_name)
  list.fetch(view_name)
end
gem_root() click to toggle source
# File lib/monocle.rb, line 84
def gem_root
  # Get the absolute path of our gem root
  File.expand_path(File.dirname(__dir__))
end
list() click to toggle source
# File lib/monocle.rb, line 22
def list
  @list ||= ListCommand.new.call
end
migrate() click to toggle source
# File lib/monocle.rb, line 38
def migrate
  logger.info "Starting materialized views migrations..."
  list.each do |key, view|
    logger.debug "Checking if #{key} is up to date..."
    view.migrate
  end
  logger.info "All done!"
end
refresh(view_name, concurrently: false) click to toggle source
# File lib/monocle.rb, line 55
def refresh(view_name, concurrently: false)
  fetch(view_name).refresh concurrently: concurrently
end
refresh_all() click to toggle source
# File lib/monocle.rb, line 59
def refresh_all
  list.each do |key, view|
    logger.info "Refreshing view #{key}..."
    view.refresh # this will be a noop for non matviews
  end
end
root() click to toggle source
# File lib/monocle.rb, line 79
def root
  # Get the absolute path of the project who is using us
  File.expand_path(Dir.pwd)
end
versions() click to toggle source
# File lib/monocle.rb, line 34
def versions
  Migration.versions
end
views_path() click to toggle source
# File lib/monocle.rb, line 75
def views_path
  File.join(root, path_to_views)
end

Protected Class Methods

configuration() click to toggle source
# File lib/monocle.rb, line 96
def configuration
  @configuration ||= Configuration.new
end
symbolize_name(name) click to toggle source
# File lib/monocle.rb, line 101
def symbolize_name(name)
  name.is_a?(String) ? name.to_sym : name
end