activerecord-database-views 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZmJmMDk3MGZhZWFkYjAzYzdlNzlmNDkxMzU1OWY4ODU5MjEyMmI0Yg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20125a212af919fae61754272c75f0d8c2f6945a
|
4
|
+
data.tar.gz: 81f76e8d0427e125550582b191bd0fea685486fd
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NDllZWEyYzhiYmFhNmE4NmUzMWU3ZmY1OTZmYmM5YmRhYjY4YWU2ZTZjZmQ1
|
11
|
-
ODM4ZjA1OTJmOWQwYWMxNDIyNzFlZGYzNThiM2Y3NmY2NDBhOTc=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YWJmMmJiZDA1ZDcwY2E5ZGRlYmU2MjBkZWVmMmMzZjRiZDE5MTdjNmY5NTky
|
14
|
-
ZmIyYWFlYjRmMzExOWU2YTU4MTFlYmEwMGRiMzliZjg2ZTc3ZmFlMzBjODMy
|
15
|
-
MmUzMjAwMjg2NTBlOTg1ZmE2YmNkN2I3NzNiNGY1YmRjNzI4ZDY=
|
6
|
+
metadata.gz: a080fe9228c20000f9ac692e41ed9929cc5e732942ddcc9874e64e43703160d2cd6f45a010d5be476365bef79192b58b98eb0aa9bebb308e8ef4029d2f106153
|
7
|
+
data.tar.gz: dc8ffdb4429c0752eecfa417b9e1631e0b46dca6c9cd1460b6d332fa0f8aeb09509e444aefa883ab290ff325aa7931c1afb2bf705bde63e7483f6cd0326d7235
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module ActiveRecord::DatabaseViews
|
2
2
|
class View
|
3
|
+
FILE_NAME_MATCHER_WITH_PREFIX = /^\d+?_(.+)/
|
4
|
+
|
3
5
|
attr_reader :path
|
4
6
|
|
5
7
|
def initialize(path)
|
@@ -15,11 +17,19 @@ module ActiveRecord::DatabaseViews
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def name
|
18
|
-
|
20
|
+
if basename =~ FILE_NAME_MATCHER_WITH_PREFIX
|
21
|
+
FILE_NAME_MATCHER_WITH_PREFIX.match(basename)[1]
|
22
|
+
else
|
23
|
+
basename
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
private
|
22
28
|
|
29
|
+
def basename
|
30
|
+
@basename ||= File.basename(path, '.sql')
|
31
|
+
end
|
32
|
+
|
23
33
|
def full_path
|
24
34
|
Rails.root.join(path)
|
25
35
|
end
|
@@ -6,22 +6,18 @@ module ActiveRecord::DatabaseViews
|
|
6
6
|
|
7
7
|
attr_reader :views
|
8
8
|
|
9
|
+
delegate :each, to: :views
|
10
|
+
|
9
11
|
def initialize
|
10
12
|
@views = view_paths.map { |path| View.new(path) }
|
11
13
|
end
|
12
14
|
|
13
15
|
def drop!
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def each
|
18
|
-
views.each { |view| yield view }
|
16
|
+
each(&:drop!)
|
19
17
|
end
|
20
18
|
|
21
19
|
def load!
|
22
|
-
while
|
23
|
-
load_view(views.first)
|
24
|
-
end
|
20
|
+
load_view(first) while first
|
25
21
|
end
|
26
22
|
|
27
23
|
private
|
@@ -29,10 +25,9 @@ module ActiveRecord::DatabaseViews
|
|
29
25
|
def load_view(view)
|
30
26
|
begin
|
31
27
|
view.load! and views.delete(view)
|
32
|
-
rescue ActiveRecord::StatementInvalid =>
|
33
|
-
if (related_view = retrieve_related_view(
|
34
|
-
load_view(related_view)
|
35
|
-
retry
|
28
|
+
rescue ActiveRecord::StatementInvalid => exception
|
29
|
+
if (related_view = retrieve_related_view(exception))
|
30
|
+
load_view(related_view) and retry
|
36
31
|
else
|
37
32
|
raise exc
|
38
33
|
end
|
@@ -46,7 +41,7 @@ module ActiveRecord::DatabaseViews
|
|
46
41
|
end
|
47
42
|
|
48
43
|
def view_paths
|
49
|
-
Dir.glob(
|
44
|
+
Dir.glob('db/views/**/*.sql').sort
|
50
45
|
end
|
51
46
|
end
|
52
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-database-views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stevo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Facilitates storing and reloading of DB views within Rails applications
|
14
14
|
email:
|
@@ -30,17 +30,17 @@ require_paths:
|
|
30
30
|
- lib
|
31
31
|
required_ruby_version: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
|
-
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
42
|
+
rubyforge_project: "[none]"
|
43
|
+
rubygems_version: 2.2.2
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Facilitates reloading of DB views
|