Module: Monocle

Defined in:
lib/monocle/view.rb,
lib/monocle.rb,
lib/monocle/railtie.rb,
lib/monocle/version.rb,
lib/monocle/migration.rb,
lib/monocle/list_command.rb,
lib/monocle/configuration.rb,
lib/monocle/version_generator.rb

Overview

An in-memory representation of the view

Defined Under Namespace

Modules: Generators Classes: BumpCommand, Configuration, DropCommand, ListCommand, Migration, Railtie, VersionGenerator, View

Constant Summary collapse

VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.bump(view_name) ⇒ Object



47
48
49
# File 'lib/monocle.rb', line 47

def bump(view_name)
  BumpCommand.new(fetch(view_name)).call
end

.configure {|configuration| ... } ⇒ Object

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

Yields:

  • (configuration)


71
72
73
# File 'lib/monocle.rb', line 71

def configure
  yield configuration if block_given?
end

.create(view_name) ⇒ Object



30
31
32
# File 'lib/monocle.rb', line 30

def create(view_name)
  fetch(view_name).create
end

.drop(view_name) ⇒ Object



26
27
28
# File 'lib/monocle.rb', line 26

def drop(view_name)
  fetch(view_name).drop
end

.fetch(view_name) ⇒ Object



89
90
91
92
# File 'lib/monocle.rb', line 89

def fetch(view_name)
  view_name = symbolize_name(view_name)
  list.fetch(view_name)
end

.gem_rootObject



84
85
86
87
# File 'lib/monocle.rb', line 84

def gem_root
  # Get the absolute path of our gem root
  File.expand_path(File.dirname(__dir__))
end

.listObject



22
23
24
# File 'lib/monocle.rb', line 22

def list
  @list ||= ListCommand.new.call
end

.migrateObject



38
39
40
41
42
43
44
45
# 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) ⇒ Object



55
56
57
# File 'lib/monocle.rb', line 55

def refresh(view_name, concurrently: false)
  fetch(view_name).refresh concurrently: concurrently
end

.refresh_allObject



59
60
61
62
63
64
# 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

.rootObject



79
80
81
82
# 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

.versionsObject



34
35
36
# File 'lib/monocle.rb', line 34

def versions
  Migration.versions
end

.views_pathObject



75
76
77
# File 'lib/monocle.rb', line 75

def views_path
  File.join(root, path_to_views)
end