-
-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathdefinition.rb
More file actions
43 lines (36 loc) · 807 Bytes
/
definition.rb
File metadata and controls
43 lines (36 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Scenic
# @api private
class Definition
def initialize(name, version, database = nil)
@name = name.to_s
@version = version.to_i
@database = database
end
def to_sql
File.read(full_path).tap do |content|
if content.empty?
raise "Define view query in #{path} before migrating."
end
end
end
def full_path
Rails.root.join(path)
end
def path
views_dir = if @database && @database != :default
"#{@database}_views"
else
"views"
end
File.join("db", views_dir, filename)
end
def version
@version.to_s.rjust(2, "0")
end
private
attr_reader :name
def filename
"#{UnaffixedName.for(name).tr(".", "_")}_v#{version}.sql"
end
end
end