prick 0.26.0 → 0.27.0
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/TODO +2 -0
- data/exe/prick +1 -1
- data/lib/builder/builder.rb +1 -0
- data/lib/builder/parser.rb +46 -5
- data/lib/ext/expand_variables.rb +27 -0
- data/lib/prick/version.rb +1 -1
- data/lib/prick.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83646fd3fd6a7fecab082cdc10ee5c3bd1330630422edf9640ff6579384aba5d
|
4
|
+
data.tar.gz: 5e49929c6b878929581e46428e036bd5bad00a0695612c6a6d6a7f2d5bcf80da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c52f1241c25e8a3aaa9fafba21abc97020ac376cf458e2ec0fba28c9f310183175c3d932515cf644615b3824663cfb891eef91e0b68f741b9e53dd8b5e74165
|
7
|
+
data.tar.gz: d10e893a58d87e5ec8b08eb66ff0744b8b6a452935b779f016db4729ad156d36ab97c81b616a328c8dd07ed52f8170575cbc18343961bec3c0e4518fc9426d31
|
data/TODO
CHANGED
data/exe/prick
CHANGED
@@ -200,7 +200,7 @@ begin
|
|
200
200
|
database, username, args.expect(0..1), force: cmd.force?, timer: cmd.time?, dump: dump)
|
201
201
|
|
202
202
|
when :make!
|
203
|
-
dump = cmd.dump? ? cmd.dump("batches")
|
203
|
+
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
204
204
|
Prick::SubCommand.make(database, username, args.expect(0..1), timer: cmd.time?, dump: dump)
|
205
205
|
|
206
206
|
when :fox!
|
data/lib/builder/builder.rb
CHANGED
data/lib/builder/parser.rb
CHANGED
@@ -8,11 +8,12 @@ module Prick
|
|
8
8
|
|
9
9
|
attr_reader :conn
|
10
10
|
attr_reader :dir
|
11
|
-
attr_reader :unit
|
11
|
+
attr_reader :unit # The singular RootBuildNode object
|
12
12
|
# attr_reader :schemas
|
13
13
|
|
14
14
|
def initialize(conn)
|
15
15
|
@conn = conn
|
16
|
+
@unit = nil
|
16
17
|
end
|
17
18
|
|
18
19
|
def parse(dir)
|
@@ -24,7 +25,7 @@ module Prick
|
|
24
25
|
|
25
26
|
private
|
26
27
|
|
27
|
-
# First
|
28
|
+
# First built unit is a RootBuildNode, the rest are regular BuildNode objects
|
28
29
|
def make_build_unit(parent, path)
|
29
30
|
if @unit
|
30
31
|
BuildNode.new(parent, path)
|
@@ -76,11 +77,51 @@ module Prick
|
|
76
77
|
unit
|
77
78
|
end
|
78
79
|
|
80
|
+
# Expand $ENVIRONMENT variable. The function implements a hierarchy of
|
81
|
+
# environments:
|
82
|
+
#
|
83
|
+
# production
|
84
|
+
# online
|
85
|
+
# development
|
86
|
+
# online
|
87
|
+
# offline
|
88
|
+
# backend
|
89
|
+
# frontend
|
90
|
+
# test
|
91
|
+
#
|
92
|
+
# If an environment doesn't exist in #dir, then the higher level
|
93
|
+
# environments are tried in turn. Eg. if the current environment is
|
94
|
+
# 'test', the algorithm expands '$ENVIRONMENT' to 'test', 'offline', and
|
95
|
+
# 'development' until an existing file is found. If no file is found, the
|
96
|
+
# algorithm returns the unexpanded value
|
97
|
+
#
|
98
|
+
def expand_environment(dir, name)
|
99
|
+
env = Prick.state.environment.to_s
|
100
|
+
file = name
|
101
|
+
if !File.exist?("#{dir}/#{file}") && name =~ /^(.*?)\$ENVIRONMENT/
|
102
|
+
while true
|
103
|
+
file = expand_variables(name, ENVIRONMENT: env)
|
104
|
+
break if File.exist? "#{dir}/#{file}"
|
105
|
+
case env
|
106
|
+
when "production"; break
|
107
|
+
when "development"; break
|
108
|
+
when "online"; env = "development"
|
109
|
+
when "offline"; env = "development"
|
110
|
+
when "backend"; env = "offline"
|
111
|
+
when "frontend"; env = "offline"
|
112
|
+
when "test"; env = "offline"
|
113
|
+
else
|
114
|
+
raise Error, "Illegal env: '#{env}'"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
return file
|
119
|
+
end
|
120
|
+
|
79
121
|
def parse_file_entry(dir, entry)
|
80
|
-
name = entry
|
81
|
-
name.sub!(/\$ENVIRONMENT/, Prick.state.environment.to_s)
|
122
|
+
name = expand_environment(dir, entry)
|
82
123
|
name.sub!(/\/$/, "")
|
83
|
-
if name =~ /^(\S+)\s+(
|
124
|
+
if name =~ /^(\S+)\s+(.+)$/ # has arguments -> exe
|
84
125
|
file = $1
|
85
126
|
args = $2.split
|
86
127
|
else
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# Expands variables in a template string. Variables are prefixed with a $ sign
|
3
|
+
# and consist of word characters (letters, digits, underscores). The name can
|
4
|
+
# be enclosed in curly braces to avoid unintended expansions. The $ sign can be
|
5
|
+
# escaped with a backslash (\), and backslashes can be escaped with another
|
6
|
+
# backslash. All occurrences of a variable in the string are replaced
|
7
|
+
#
|
8
|
+
# The str argument is the template string and the variables argument is a hash
|
9
|
+
# from variable name (Symbol) to variable value
|
10
|
+
#
|
11
|
+
# Note that the characters '\x00' and '\x01' are used internally and may not be
|
12
|
+
# present in the template string
|
13
|
+
#
|
14
|
+
def expand_variables(str, variables) # ChatGPT
|
15
|
+
# Replace escaped bashslashes and dollar signs
|
16
|
+
str = str.gsub('\\\\', "\x00").gsub('\\$', "\x01")
|
17
|
+
|
18
|
+
# Expand variables
|
19
|
+
str.gsub!(/\$(\w+)\b|\$\{(\w+)\}/) do |match| # Strange that '\b' is necessary
|
20
|
+
key = ($1 || $2).to_sym
|
21
|
+
variables[key] || match
|
22
|
+
end
|
23
|
+
|
24
|
+
# Restore escaped characters
|
25
|
+
str.gsub("\x00", '\\').gsub("\x01", '$')
|
26
|
+
end
|
27
|
+
|
data/lib/prick/version.rb
CHANGED
data/lib/prick.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semantic
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/builder/node.rb
|
174
174
|
- lib/builder/node_pool.rb
|
175
175
|
- lib/builder/parser.rb
|
176
|
+
- lib/ext/expand_variables.rb
|
176
177
|
- lib/local/command.rb
|
177
178
|
- lib/local/git.rb
|
178
179
|
- lib/local/timer.rb
|