prick 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fcaa84e14ed58667eaa0752b5dec5ba5786f3a32b2a598d8d78ab6636817e65
4
- data.tar.gz: b9582bdb7d6733b0aaf50675581135e2c04fabe322d7c8ccbec5481569a7ec04
3
+ metadata.gz: 83646fd3fd6a7fecab082cdc10ee5c3bd1330630422edf9640ff6579384aba5d
4
+ data.tar.gz: 5e49929c6b878929581e46428e036bd5bad00a0695612c6a6d6a7f2d5bcf80da
5
5
  SHA512:
6
- metadata.gz: 72cb0ca152e3805131079e3e9d473eb1fb8623d571bbdeddd398e943dc199bb31f5f0c1e94f78c163211dbc5bd2fcad5858e3ad11331e6a5fea70c898d07a047
7
- data.tar.gz: bdd15924608544c695c2932b1a7e3581307917bced9f2a449caeb56962aa17546ed8a6314ce5f7450a519c01288c883d1d82d1980145d81ad1e9928e906ce207
6
+ metadata.gz: 7c52f1241c25e8a3aaa9fafba21abc97020ac376cf458e2ec0fba28c9f310183175c3d932515cf644615b3824663cfb891eef91e0b68f741b9e53dd8b5e74165
7
+ data.tar.gz: d10e893a58d87e5ec8b08eb66ff0744b8b6a452935b779f016db4729ad156d36ab97c81b616a328c8dd07ed52f8170575cbc18343961bec3c0e4518fc9426d31
data/TODO CHANGED
@@ -1,3 +1,5 @@
1
+ o Use standard directory layout
2
+
1
3
  o Have the following entries
2
4
 
3
5
  sql: SQL_STATEMENT
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").to_sym : nil
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!
@@ -87,6 +87,7 @@ module Prick
87
87
  end
88
88
  batch.nodes << node
89
89
  end
90
+
90
91
  @batches << batch if batch
91
92
  end
92
93
 
@@ -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 build unit is a RootBuildNode, the rest are regular BuildNode objects
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.dup
81
- name.sub!(/\$ENVIRONMENT/, Prick.state.environment.to_s)
122
+ name = expand_environment(dir, entry)
82
123
  name.sub!(/\/$/, "")
83
- if name =~ /^(\S+)\s+(.*)$/ # exe
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prick
4
- VERSION = "0.26.0"
4
+ VERSION = "0.27.0"
5
5
  end
data/lib/prick.rb CHANGED
@@ -12,6 +12,7 @@ module Prick
12
12
  end
13
13
 
14
14
  require 'prick/constants.rb'
15
+ require 'ext/expand_variables.rb'
15
16
 
16
17
  require 'local/command.rb'
17
18
  require 'local/git.rb'
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.26.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-18 00:00:00.000000000 Z
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