prick 0.26.0 → 0.27.1

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: fe266587f9311853dc79a6eee9ff2732ba265fd50ce1fb69fb0ba1d8f2018f5a
4
+ data.tar.gz: f364180b63248c6b1cbc963cad889770538aabfbc5b0ec9d12aabe97e91fd1dc
5
5
  SHA512:
6
- metadata.gz: 72cb0ca152e3805131079e3e9d473eb1fb8623d571bbdeddd398e943dc199bb31f5f0c1e94f78c163211dbc5bd2fcad5858e3ad11331e6a5fea70c898d07a047
7
- data.tar.gz: bdd15924608544c695c2932b1a7e3581307917bced9f2a449caeb56962aa17546ed8a6314ce5f7450a519c01288c883d1d82d1980145d81ad1e9928e906ce207
6
+ metadata.gz: 0ab04d20f8169352ac7c6e181b053c3e5271e60c5109af444fd8abb37ad3ce5d101e37f2c2ee06c801b0b7a18662fad65384b6434e592abefd18a1c48b7ee442
7
+ data.tar.gz: f8108b5acec772b9ee63b7f8acc46aa9a1b54fea79766cd1c7ed449a8d069484d6ffd74296a6f90d2eac9dc368656d680bdf03e0ab9f140d336cac46ea104219
data/TODO CHANGED
@@ -1,3 +1,6 @@
1
+ o Make it possible to define (nested) environments
2
+ o Use standard directory layout
3
+
1
4
  o Have the following entries
2
5
 
3
6
  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.1"
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'
@@ -40,7 +40,7 @@ require 'postspec_helper'
40
40
  require 'prick_helper'
41
41
 
42
42
  Postspec.configure do |config|
43
- config.database = "mikras"
43
+ config.database = Prick.state.database
44
44
  # config.anchors = "..."
45
45
  config.mode = :seed
46
46
  config.reflections = Prick::REFLECTIONS_PATH if File.exist?(Prick::REFLECTIONS_PATH)
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.1
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-21 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