reshape_helper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/reshape_helper.rb +65 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 410b1f790d9398e86eccb0f3c1f2f9e45544febe44d3b4d63efe97b95064a43d
|
4
|
+
data.tar.gz: 10d1570b1b1a0ab5e0d159ba0c73d97fbe7a0795def297650fe9a63bf74e4a3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d59e84ea647462a3b680f7883f596788ae02394e64d5e32d049c74ac76fc54f90fcc0c3230d7175f6c3f23671ed315da439b264c405b54d360328dd8f0ad828
|
7
|
+
data.tar.gz: 3317865b59c062e9be6b57473fa69edd15791a90ab112a2351fee54f1ba0f0eabe121cc17e1a0bb1ef5c753e2e4596e409850e3dd3ff8f35e90268aae3df7909
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "toml"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
DEFAULT_SEARCH_PATH = '"$user", public'
|
5
|
+
|
6
|
+
class ReshapeHelper
|
7
|
+
def self.schema_query(*dirs)
|
8
|
+
# Default to searching the migrations folder
|
9
|
+
if dirs.empty?
|
10
|
+
dirs = ["migrations"]
|
11
|
+
end
|
12
|
+
|
13
|
+
migrations = self.find_migrations(dirs)
|
14
|
+
|
15
|
+
search_path = if migrations.empty?
|
16
|
+
DEFAULT_SEARCH_PATH
|
17
|
+
else
|
18
|
+
"migration_#{migrations.last()}"
|
19
|
+
end
|
20
|
+
|
21
|
+
"SET search_path TO #{search_path}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.find_migrations(dirs)
|
27
|
+
# Find all files in the specified folders
|
28
|
+
files = dirs.flat_map do |dir|
|
29
|
+
Dir.glob("#{dir}/*")
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sort files by their names
|
33
|
+
files = files.sort_by { |file| File.basename(file, ".*") }
|
34
|
+
|
35
|
+
migrations = files.map do |file_path|
|
36
|
+
contents = File.read(file_path)
|
37
|
+
migration = self.decode_migration_file(file_path, contents)
|
38
|
+
|
39
|
+
if migration.key?("name")
|
40
|
+
migration["name"]
|
41
|
+
else
|
42
|
+
# Use the file name as migration name if no name is set in the migration file
|
43
|
+
File.basename(file_path, ".*")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
migrations
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.decode_migration_file(file_path, contents)
|
51
|
+
if contents.empty?
|
52
|
+
return {}
|
53
|
+
end
|
54
|
+
|
55
|
+
extension = File.extname(file_path)
|
56
|
+
case extension
|
57
|
+
when ".toml"
|
58
|
+
TOML::Parser.new(contents).parsed
|
59
|
+
when ".json"
|
60
|
+
JSON.parse(contents)
|
61
|
+
else
|
62
|
+
raise "Unrecognized migration file extension #{extension}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reshape_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabian Lindfors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: fabian@flapplabs.se
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/reshape_helper.rb
|
20
|
+
homepage: https://github.com/fabianlindfors/reshape-ruby
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.2.32
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: A Ruby helper library for applications using Reshape
|
43
|
+
test_files: []
|