ar-monocle 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e87742c40793bc87a080779df7810ce565acf4a
4
- data.tar.gz: f660aa91f8e80cc8da97092da30a0e4e4ca4ac6b
3
+ metadata.gz: 526a9406fbfc24cd93f3c599076c3bf891ec1239
4
+ data.tar.gz: 953fc1ec3bafa1c8c516ee3c2cb0c0e3a04be615
5
5
  SHA512:
6
- metadata.gz: 3a00f377c8500d1f45a2cf0986bb2dff9ca490c20cd244b51209365a97d24eeb940f1dcbd4392383fa754a7cf967ab6f50ef869a11d4e4d5542fd70ef4f0ec3e
7
- data.tar.gz: 52aaa8db222c5519a4bd47eace5726768db6ff962f0f9f967c2cb9e9f10babbc320f48cb39f59e96025863213fce94e047e554d5624cc0dbbf7319f2206424e9
6
+ metadata.gz: 144cbbef782122cb73820116c47aa89bd32ae292ac3e82ea7ef89850d228d0aa61d4d2fbfbf86b2ad7bf81ecaa680eba1ec2d51d9b2f4561213595de918198d3
7
+ data.tar.gz: 2295282ecd7a50af58f8a4deae568168a68f900518c50e2afc6db37dc17cc9789e43f527da874f0ebe68f053a9f8132baaef7e221f9119be1ad386d706aeb754
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar-monocle (0.1.0)
4
+ ar-monocle (0.1.2)
5
5
  activerecord (>= 4, < 6)
6
6
  activesupport (>= 4, < 6)
7
7
  rake
@@ -9,13 +9,13 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (5.0.0.1)
13
- activesupport (= 5.0.0.1)
14
- activerecord (5.0.0.1)
15
- activemodel (= 5.0.0.1)
16
- activesupport (= 5.0.0.1)
12
+ activemodel (5.0.2)
13
+ activesupport (= 5.0.2)
14
+ activerecord (5.0.2)
15
+ activemodel (= 5.0.2)
16
+ activesupport (= 5.0.2)
17
17
  arel (~> 7.0)
18
- activesupport (5.0.0.1)
18
+ activesupport (5.0.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (~> 0.7)
21
21
  minitest (~> 5.1)
@@ -26,7 +26,7 @@ GEM
26
26
  database_cleaner (1.5.3)
27
27
  diff-lcs (1.3)
28
28
  dotenv (2.2.0)
29
- i18n (0.7.0)
29
+ i18n (0.8.1)
30
30
  metaclass (0.0.4)
31
31
  method_source (0.8.2)
32
32
  minitest (5.10.1)
@@ -55,7 +55,7 @@ GEM
55
55
  rspec-support (3.5.0)
56
56
  slop (3.6.0)
57
57
  thread_safe (0.3.6)
58
- tzinfo (1.2.2)
58
+ tzinfo (1.2.3)
59
59
  thread_safe (~> 0.1)
60
60
 
61
61
  PLATFORMS
@@ -2,6 +2,7 @@
2
2
  require "active_support/core_ext/module/delegation"
3
3
  require 'active_record'
4
4
 
5
+ require 'monocle/configuration'
5
6
  require 'monocle/railtie' if defined?(Rails)
6
7
 
7
8
  require "monocle/version"
@@ -13,71 +14,81 @@ require "monocle/bump_command"
13
14
  require "monocle/list_command"
14
15
 
15
16
  module Monocle
16
- def self.list
17
- @list ||= ListCommand.new.call
18
- end
19
-
20
- def self.drop(view_name)
21
- fetch(view_name).drop
22
- end
23
17
 
24
- def self.create(view_name)
25
- fetch(view_name).create
26
- end
18
+ class << self
19
+ delegate :path_to_views, :logger, to: :configuration
27
20
 
28
- def self.versions
29
- Migration.versions
30
- end
21
+ def list
22
+ @list ||= ListCommand.new.call
23
+ end
31
24
 
32
- def self.migrate
33
- logger.info "Starting materialized views migrations..."
34
- list.each do |key, view|
35
- logger.debug "Checking if #{key} is up to date..."
36
- view.migrate
25
+ def drop(view_name)
26
+ fetch(view_name).drop
37
27
  end
38
- logger.info "All done!"
39
- end
40
28
 
41
- def self.bump(view_name)
42
- BumpCommand.new(fetch(view_name)).call
43
- end
29
+ def create(view_name)
30
+ fetch(view_name).create
31
+ end
44
32
 
45
- def self.refresh(view_name, concurrently: false)
46
- fetch(view_name).refresh concurrently: concurrently
47
- end
33
+ def versions
34
+ Migration.versions
35
+ end
48
36
 
49
- def self.logger
50
- # FIXME: This will need to be configurable
51
- @logger ||= if defined?(Rails)
52
- Rails.logger
53
- else
54
- Logger.new(STDOUT).tap do |logger|
55
- logger.level = Logger::ERROR
37
+ def migrate
38
+ logger.info "Starting materialized views migrations..."
39
+ list.each do |key, view|
40
+ logger.debug "Checking if #{key} is up to date..."
41
+ view.migrate
56
42
  end
43
+ logger.info "All done!"
57
44
  end
58
- end
59
45
 
60
- def self.views_path
61
- # FIXME: This will need to be configurable
62
- @views_path ||= if defined?(Rails)
63
- File.join Rails.root, "db/views"
64
- else
65
- File.join Monocle.root, "db/views"
46
+ def bump(view_name)
47
+ BumpCommand.new(fetch(view_name)).call
66
48
  end
67
- end
68
49
 
69
- def self.root
70
- File.expand_path(File.dirname(__dir__))
71
- end
50
+ def refresh(view_name, concurrently: false)
51
+ fetch(view_name).refresh concurrently: concurrently
52
+ end
72
53
 
73
- protected
54
+ # Enables you to configure things in a block, i.e
55
+ # Monocle.configure do |config|
56
+ # config.logger = MyLogger.new
57
+ # config.path_to_views = "my/different/path/to/my/sql/files"
58
+ # end
59
+ def configure
60
+ yield configuration if block_given?
61
+ end
74
62
 
75
- def self.fetch(view_name)
76
- view_name = symbolize_name(view_name)
77
- list.fetch(view_name)
78
- end
63
+ def views_path
64
+ File.join(root, path_to_views)
65
+ end
66
+
67
+ def root
68
+ # Get the absolute path of the project who is using us
69
+ File.expand_path(Dir.pwd)
70
+ end
71
+
72
+ def gem_root
73
+ # Get the absolute path of our gem root
74
+ File.expand_path(File.dirname(__dir__))
75
+ end
79
76
 
80
- def self.symbolize_name(name)
81
- name.is_a?(String) ? name.to_sym : name
77
+ def fetch(view_name)
78
+ view_name = symbolize_name(view_name)
79
+ list.fetch(view_name)
80
+ end
81
+
82
+ protected
83
+
84
+ def configuration
85
+ @configuration ||= Configuration.new
86
+ end
87
+
88
+
89
+ def symbolize_name(name)
90
+ name.is_a?(String) ? name.to_sym : name
91
+ end
82
92
  end
93
+
83
94
  end
@@ -0,0 +1,16 @@
1
+ module Monocle
2
+ class Configuration
3
+ attr_accessor :path_to_views, :logger
4
+
5
+ # Define a custom logger
6
+ def logger
7
+ @logger ||= (defined?(Rails) ? Rails.logger : Logger.new('monocle.log'))
8
+ end
9
+
10
+ # The relative path to where views are stored, relative to the root of the
11
+ # project
12
+ def path_to_views
13
+ @path_to_views ||= "db/views"
14
+ end
15
+ end
16
+ end
@@ -1,11 +1,11 @@
1
1
  module Monocle
2
2
  class Railtie < Rails::Railtie
3
3
  rake_tasks do
4
- load File.join(Monocle.root, "lib/tasks/monocle.rake")
4
+ load File.join(Monocle.gem_root, "lib/tasks/monocle.rake")
5
5
  end
6
6
 
7
7
  generators do
8
- Dir[File.join(Monocle.root, "lib/monocle/generators/*.rb")].each { |f| require f }
8
+ Dir[File.join(Monocle.gem_root, "lib/monocle/generators/*.rb")].each { |f| require f }
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Monocle
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -40,6 +40,19 @@ module Monocle
40
40
  Migration.find_or_create_by version: slug
41
41
  dependants.each &:create
42
42
  true
43
+ rescue ActiveRecord::StatementInvalid => e
44
+ # We may have another new view coming that this view depend on
45
+ # if the relation name is included on our list of views, we create
46
+ # that first and then retry
47
+ if e.message =~ /PG::UndefinedTable/ &&
48
+ e.message.scan(/relation \"(\w+)\" does not exist/) &&
49
+ list.keys.include?($1.to_sym)
50
+ warn "Can't create #{name} because it depends on #{$1}, creating that first..."
51
+ list.fetch($1.to_sym).create
52
+ retry
53
+ else
54
+ fail e
55
+ end
43
56
  end
44
57
 
45
58
  def migrate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-monocle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Bighetti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,6 +178,7 @@ files:
178
178
  - bin/setup
179
179
  - lib/monocle.rb
180
180
  - lib/monocle/bump_command.rb
181
+ - lib/monocle/configuration.rb
181
182
  - lib/monocle/generators/install_generator.rb
182
183
  - lib/monocle/generators/matview_generator.rb
183
184
  - lib/monocle/generators/view_generator.rb