forked from scenic-views/scenic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix scenic-views#261
- Loading branch information
Showing
9 changed files
with
77 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require_relative "definition" | ||
|
||
module Scenic | ||
# @api private | ||
class Definitions | ||
include Enumerable | ||
include Comparable | ||
|
||
attr_reader :name, :views_directory_path | ||
|
||
def initialize(name) | ||
@name = name | ||
end | ||
|
||
def each | ||
versions.each do |version| | ||
yield Scenic::Definition.new(name, version) | ||
end | ||
end | ||
|
||
def <=>(definition_a, definition_b) | ||
definition_a.version <=> definition_b.version | ||
end | ||
|
||
def versions | ||
@versions ||= Dir.entries(Scenic.configuration.definitions_path) | ||
.map { |name| version_regex.match(name).try(:[], "version").try(:to_i) } | ||
.compact | ||
.sort | ||
end | ||
|
||
private | ||
|
||
def version_regex | ||
/\A#{name}_v(?<version>\d+)\.sql\z/ | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
module ViewDefinitionHelpers | ||
def with_view_definition(name, version, schema) | ||
definition = Scenic::Definition.new(name, version) | ||
FileUtils.mkdir_p(File.dirname(definition.full_path)) | ||
File.open(definition.full_path, "w") { |f| f.write(schema) } | ||
FileUtils.mkdir_p(File.dirname(definition.path)) | ||
File.open(definition.path, "w") { |f| f.write(schema) } | ||
yield | ||
ensure | ||
FileUtils.rm_f(definition.full_path) | ||
FileUtils.rm_f(definition.path) | ||
end | ||
end |