activerecord_views 0.0.15 → 0.0.16
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 +4 -4
- data/lib/active_record_views/extension.rb +3 -8
- data/lib/active_record_views/registered_view.rb +1 -1
- data/lib/active_record_views/version.rb +1 -1
- data/lib/active_record_views.rb +8 -0
- data/lib/tasks/active_record_views.rake +1 -0
- data/spec/active_record_views_extension_spec.rb +25 -0
- data/spec/internal/Rakefile +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3665d75c1a7665c0c436548c6aef0b045cf65a6
|
4
|
+
data.tar.gz: 411bd452c4ffc8afaf05e9a06ea2bf708e2c6b54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0693473e52cbd7add2dfc0ba7d95c700e877b39ab8cb97f0a38eba7be10424e788534788ab1d48f37b1066e75a16bfc82c4ee06c018eb6fc3ccc138a861fa623'
|
7
|
+
data.tar.gz: 8f7940ea28efbee5f26fdd0ec6273b0fa665bc876c5634d6bdc37e7633ea7e86b1572079b1b52098e2163da385cdf187326bba53992c0799b966697ebc44f82c
|
@@ -5,8 +5,8 @@ module ActiveRecordViews
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
def self.currently_migrating?
|
8
|
-
if defined?(Rake) && Rake.
|
9
|
-
Rake.application.top_level_tasks.
|
8
|
+
if defined?(Rake) && Rake.respond_to?(:application)
|
9
|
+
Rake.application.top_level_tasks.any? { |task_name| task_name =~ /^db:migrate($|:)/ }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -23,12 +23,7 @@ module ActiveRecordViews
|
|
23
23
|
sql ||= begin
|
24
24
|
sql_path = ActiveRecordViews.find_sql_file(self.name.underscore)
|
25
25
|
ActiveRecordViews.register_for_reload self, sql_path
|
26
|
-
|
27
|
-
if sql_path.end_with?('.erb')
|
28
|
-
ERB.new(File.read(sql_path)).result
|
29
|
-
else
|
30
|
-
File.read(sql_path)
|
31
|
-
end
|
26
|
+
ActiveRecordViews.read_sql_file(sql_path)
|
32
27
|
end
|
33
28
|
|
34
29
|
ActiveRecordViews.create_view self.connection, self.table_name, self.name, sql, self.view_options
|
@@ -18,7 +18,7 @@ module ActiveRecordViews
|
|
18
18
|
|
19
19
|
def reload!
|
20
20
|
if File.exist? sql_path
|
21
|
-
ActiveRecordViews.create_view model_class.connection, model_class.table_name, model_class.name,
|
21
|
+
ActiveRecordViews.create_view model_class.connection, model_class.table_name, model_class.name, ActiveRecordViews.read_sql_file(sql_path), model_class.view_options
|
22
22
|
else
|
23
23
|
ActiveRecordViews.drop_view model_class.connection, model_class.table_name
|
24
24
|
end
|
data/lib/active_record_views.rb
CHANGED
@@ -28,6 +28,14 @@ module ActiveRecordViews
|
|
28
28
|
raise "could not find #{name}.sql"
|
29
29
|
end
|
30
30
|
|
31
|
+
def self.read_sql_file(sql_path)
|
32
|
+
if sql_path.end_with?('.erb')
|
33
|
+
ERB.new(File.read(sql_path)).result
|
34
|
+
else
|
35
|
+
File.read(sql_path)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
31
39
|
def self.without_transaction(connection)
|
32
40
|
in_transaction = if connection.respond_to? :transaction_open?
|
33
41
|
connection.transaction_open?
|
@@ -13,6 +13,7 @@ Rake::Task['db:structure:dump'].enhance do
|
|
13
13
|
set_psql_env(config)
|
14
14
|
end
|
15
15
|
|
16
|
+
require 'shellwords'
|
16
17
|
system("pg_dump --data-only --table=active_record_views #{Shellwords.escape config['database']} >> #{Shellwords.escape filename}")
|
17
18
|
raise 'active_record_views metadata dump failed' unless $?.success?
|
18
19
|
|
@@ -59,6 +59,31 @@ describe ActiveRecordViews::Extension do
|
|
59
59
|
test_request # trigger cleanup
|
60
60
|
end
|
61
61
|
|
62
|
+
it 'reloads the database view when external ERB SQL file is modified' do
|
63
|
+
['foo 42', 'bar 42'].each do |sql|
|
64
|
+
expect(ActiveRecordViews).to receive(:create_view).with(
|
65
|
+
anything,
|
66
|
+
'modified_erb_file_test_models',
|
67
|
+
'ModifiedErbFileTestModel',
|
68
|
+
sql,
|
69
|
+
{}
|
70
|
+
).once.ordered
|
71
|
+
end
|
72
|
+
|
73
|
+
with_temp_sql_dir do |temp_dir|
|
74
|
+
sql_file = File.join(temp_dir, 'modified_erb_file_test_model.sql.erb')
|
75
|
+
update_file sql_file, 'foo <%= 2*3*7 %>'
|
76
|
+
|
77
|
+
class ModifiedErbFileTestModel < ActiveRecord::Base
|
78
|
+
is_view
|
79
|
+
end
|
80
|
+
|
81
|
+
update_file sql_file, 'bar <%= 2*3*7 %>'
|
82
|
+
test_request
|
83
|
+
end
|
84
|
+
test_request # trigger cleanup
|
85
|
+
end
|
86
|
+
|
62
87
|
it 'drops the view if the external SQL file is deleted' do
|
63
88
|
with_temp_sql_dir do |temp_dir|
|
64
89
|
sql_file = File.join(temp_dir, 'deleted_file_test_model.sql')
|
data/spec/internal/Rakefile
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Weathered
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.6.11
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Automatic database view creation for ActiveRecord
|