biran 0.1.11 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/config/_my_config.yml.erb +2 -0
- data/config/app_config.yml +26 -0
- data/lib/biran/configurinator.rb +15 -4
- data/lib/biran/erb_config.rb +31 -9
- data/lib/biran/exceptions.rb +16 -0
- data/lib/biran/version.rb +1 -1
- data/lib/biran.rb +1 -0
- data/lib/tasks/biran_tasks.rake +23 -2
- metadata +33 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 724bb696cb3fefd277f0d8c892eab6a3bb247fe2cf8015fc721c9d79f5c3fc78
|
4
|
+
data.tar.gz: 00af99015b69fa0d49f5ebd4f67fa237729416a1ae9aacbf81bb0bd1aab54482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4613fff5623383163a13cb4592c4b869efbdd0ac08b81494f0e6db4e80ef8356d44ff538dcd03b09df873bff1484010fbd093f045f436d4c19d9e6ec6e4806eb
|
7
|
+
data.tar.gz: 45744b7d551dbd3f3df0d841fc9fcf8de8cda94fdafae3c20a05545e3b708acde2cb9378fbf69dc39ad149dcc2369c174e53834947c7c55088cec4d9f6a75f17
|
data/README.md
CHANGED
@@ -302,7 +302,39 @@ app:
|
|
302
302
|
extension: ‘.yml’
|
303
303
|
output_dir: ‘/srv/app/current/reports’
|
304
304
|
output_name: ‘user_report’
|
305
|
+
```
|
306
|
+
|
307
|
+
In a more advanced example, you can generate multiple files from the same template by setting the `config_index_list` option. If you set this as a list of indexes, then a file will be generated for each index. The index number
|
308
|
+
will get passed to the template as an instance variable (`@config_index`) and can be used to look up a specific version of values from the config file. The file that is generated will respect the normal naming, including using the `output_name` option, however, it will append the
|
309
|
+
index number to the end of the file name. If the name was going to be special_file, and you add an index list of `[1,2]`, two files will get generated named `special_file-1` and `special_file-2`.
|
310
|
+
Advanced example from `config/app:.yml`:
|
311
|
+
```
|
312
|
+
app:
|
313
|
+
files_to_generate:
|
314
|
+
reports:
|
315
|
+
extension: '.yml'
|
316
|
+
config_index_list:
|
317
|
+
- one
|
318
|
+
- two
|
319
|
+
reports:
|
320
|
+
default: &reports_default_values
|
321
|
+
some_value: 'some_value'
|
322
|
+
other_value: 'other_value'
|
323
|
+
one:
|
324
|
+
<<: *reports_default_values
|
325
|
+
two:
|
326
|
+
<<: *reports_default_values
|
327
|
+
some_value: 'my_value'
|
328
|
+
```
|
329
|
+
Then in your template file you can use the index to get the proper config for each generated file. This allows you to reuse the same template to generate multiple files, each with different content. This is useful for generating service config files, like for sidekiq workers.
|
330
|
+
The config above would generate two files: `config/reports-one.yml` and `config/reports-two.yml`, using the content from each index block as specified in the following simple template example.
|
305
331
|
```
|
332
|
+
<% index = "{@config_index}" -%>
|
333
|
+
defaults:
|
334
|
+
:some_value: <%= @app_config[:reports][index.to_sym][:some_value] %>
|
335
|
+
:other_value: <%= @app_config[:reports][index.to_sym][:other_value] %>
|
336
|
+
```
|
337
|
+
|
306
338
|
### vhost_public_dirname
|
307
339
|
**Type: string
|
308
340
|
Default: 'public'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
app:
|
3
|
+
base_path: <%= Dir.pwd %>
|
4
|
+
use_capistrano: false
|
5
|
+
files_to_generate:
|
6
|
+
my_config:
|
7
|
+
extension: '.yml'
|
8
|
+
my_first_value: 1
|
9
|
+
my_second_value: 2
|
10
|
+
nested_values: &nested_defaults
|
11
|
+
my_third_value: 3
|
12
|
+
my_fourth_value: 4
|
13
|
+
|
14
|
+
test:
|
15
|
+
<<: *defaults
|
16
|
+
my_first_value: 11
|
17
|
+
nested_values:
|
18
|
+
<<: *nested_defaults
|
19
|
+
my_third_value: 13
|
20
|
+
|
21
|
+
development:
|
22
|
+
<<: *defaults
|
23
|
+
my_first_value: 11
|
24
|
+
nested_values:
|
25
|
+
<<: *nested_defaults
|
26
|
+
my_third_value: 13
|
data/lib/biran/configurinator.rb
CHANGED
@@ -30,12 +30,17 @@ module Biran
|
|
30
30
|
.tap { |files_list| files_list.each(&sanitize_config_files(files_list)) }
|
31
31
|
end
|
32
32
|
|
33
|
-
def create(name:, extension:, output_dir: nil, output_name: nil)
|
33
|
+
def create(name:, extension:, output_dir: nil, output_name: nil, config_index_list: [])
|
34
34
|
output_dir ||= config_dir
|
35
35
|
output_name ||= name
|
36
36
|
generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir, output_name)
|
37
37
|
generated_file.bindings = bindings
|
38
|
-
generated_file.save!
|
38
|
+
return generated_file.save! unless config_index_list.any?
|
39
|
+
config_index_list.each do |config_index|
|
40
|
+
generated_file.output_name = "#{output_name}-#{config_index}"
|
41
|
+
generated_file.template_config_index = config_index
|
42
|
+
generated_file.save!
|
43
|
+
end
|
39
44
|
end
|
40
45
|
|
41
46
|
private
|
@@ -82,7 +87,7 @@ module Biran
|
|
82
87
|
def process_config_file(config_file)
|
83
88
|
config_file_contents = File.read(config_file)
|
84
89
|
config_file_contents = ERB.new(config_file_contents).result
|
85
|
-
config_file_contents =
|
90
|
+
config_file_contents = yaml_load(config_file_contents)
|
86
91
|
config_file_contents[env].deep_symbolize_keys!
|
87
92
|
rescue Errno::ENOENT
|
88
93
|
raise "Missing config file: #{config_file}"
|
@@ -109,7 +114,7 @@ module Biran
|
|
109
114
|
end
|
110
115
|
|
111
116
|
def sanitize_config_files files_list
|
112
|
-
lambda do |file, _|
|
117
|
+
lambda do |(file, _)|
|
113
118
|
files_list[file] ||= {extension: ''}
|
114
119
|
ext = files_list[file].fetch(:extension, '').strip
|
115
120
|
ext.prepend('.') unless ext.start_with?('.') || ext.empty?
|
@@ -117,6 +122,12 @@ module Biran
|
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
125
|
+
def yaml_load data_content
|
126
|
+
# Ruby 3.1 with Psych 4 allows yaml-aliases only in direct manner
|
127
|
+
return YAML.safe_load(data_content, [], [], true) if defined?(Psych::VERSION) && Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0')
|
128
|
+
YAML.safe_load(data_content, aliases: true)
|
129
|
+
end
|
130
|
+
|
120
131
|
def filtered_config
|
121
132
|
@filtered_config ||= config.except(*configuration.app_setup_blocks)
|
122
133
|
end
|
data/lib/biran/erb_config.rb
CHANGED
@@ -1,34 +1,56 @@
|
|
1
1
|
module Biran
|
2
2
|
class ERBConfig
|
3
|
-
attr_reader :output_dir, :source_dir, :name, :extension, :config, :
|
4
|
-
attr_accessor :bindings
|
3
|
+
attr_reader :output_dir, :source_dir, :name, :extension, :config, :template_contents
|
4
|
+
attr_accessor :bindings, :output_name, :template_config_index
|
5
|
+
|
6
|
+
DEFAULT_TEMPLATE_CONFIG_INDEX = 1
|
5
7
|
|
6
8
|
def initialize(config, name, extension, source, output_dir, output_name)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
before_process_erb do
|
10
|
+
@name = name
|
11
|
+
@extension = extension
|
12
|
+
@config = config
|
13
|
+
@source_dir = source
|
14
|
+
@output_dir = output_dir
|
15
|
+
@output_name = output_name
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def save!
|
16
20
|
File.open(File.join(output_dir, "#{output_name}#{extension}"), 'w') do |f|
|
17
|
-
f.print
|
21
|
+
f.print template_contents.result(build_erb_env.call)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
22
26
|
|
27
|
+
def before_process_erb
|
28
|
+
yield
|
29
|
+
raise ArgumentError unless process_erb_ready?
|
30
|
+
@template_contents = process_erb
|
31
|
+
rescue ArgumentError
|
32
|
+
e_message = "Settings required to determine template name for #{name} are not configured"
|
33
|
+
raise Biran::ConfigSyntaxError, e_message
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_erb_ready?
|
37
|
+
@name &&
|
38
|
+
@extension &&
|
39
|
+
@source_dir
|
40
|
+
end
|
41
|
+
|
23
42
|
def process_erb
|
24
43
|
config_erb_file = File.join(source_dir, "_#{name}#{extension}.erb")
|
25
44
|
ERB.new(File.read(config_erb_file), nil, '-')
|
45
|
+
rescue Errno::ENOENT
|
46
|
+
raise Biran::ConfigSyntaxError, "Missing template file for #{name}: #{config_erb_file}"
|
26
47
|
end
|
27
48
|
|
28
49
|
def build_erb_env
|
29
50
|
proc do
|
30
51
|
@environment = config[:env]
|
31
52
|
@app_config = config
|
53
|
+
@config_index = template_config_index || DEFAULT_TEMPLATE_CONFIG_INDEX
|
32
54
|
|
33
55
|
@bindings.each(&assign_instance_vars) unless @bindings.nil?
|
34
56
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Biran
|
2
|
+
class ConfigSyntaxError < ::StandardError
|
3
|
+
def initialize(msg=nil)
|
4
|
+
@msg = msg || 'Missing required argument or bad formatting in config file'
|
5
|
+
set_backtrace []
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
@msg
|
10
|
+
end
|
11
|
+
|
12
|
+
def p_warning
|
13
|
+
"Warning: #{@msg}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/biran/version.rb
CHANGED
data/lib/biran.rb
CHANGED
data/lib/tasks/biran_tasks.rake
CHANGED
@@ -1,18 +1,39 @@
|
|
1
1
|
namespace :config do
|
2
2
|
config = Biran::Configurinator.new
|
3
3
|
|
4
|
-
desc 'Generate new config files'
|
5
|
-
task :
|
4
|
+
desc 'Legacy - Generate all new config files'
|
5
|
+
task :generate_legacy do
|
6
6
|
Rake::Task['config:generate_with_deps'].enhance config.file_tasks
|
7
7
|
Rake::Task['config:generate_with_deps'].invoke
|
8
8
|
end
|
9
9
|
|
10
10
|
task :generate_with_deps
|
11
11
|
|
12
|
+
desc 'Generate all new config files'
|
13
|
+
task :generate do
|
14
|
+
error_count = 0
|
15
|
+
config.file_tasks.each do |task|
|
16
|
+
Rake::Task["config:#{task}"].invoke
|
17
|
+
rescue Biran::ConfigSyntaxError => e
|
18
|
+
error_count += 1
|
19
|
+
puts e.p_warning
|
20
|
+
next
|
21
|
+
end
|
22
|
+
|
23
|
+
abort 'Errors in creating config files' unless error_count == 0
|
24
|
+
end
|
25
|
+
|
12
26
|
config.files_to_generate.each do |file_name, options|
|
13
27
|
desc %(Generate the #{file_name}#{options.fetch(:extension, '')} config file)
|
14
28
|
task file_name do
|
15
29
|
config.create name: file_name, **options
|
30
|
+
rescue ArgumentError => e
|
31
|
+
e_message = "Missing required argument or bad formatting in config file for #{file_name}"
|
32
|
+
e.set_backtrace([])
|
33
|
+
raise Biran::ConfigSyntaxError, e_message
|
34
|
+
rescue Biran::ConfigSyntaxError => e
|
35
|
+
e.set_backtrace([])
|
36
|
+
raise Biran::ConfigSyntaxError, e.message
|
16
37
|
end
|
17
38
|
end
|
18
39
|
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biran
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- javierg
|
8
8
|
- brlanier
|
9
9
|
- seancookr
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-09-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -44,6 +44,9 @@ dependencies:
|
|
44
44
|
name: rails
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '5.0'
|
47
50
|
- - ">="
|
48
51
|
- !ruby/object:Gem::Version
|
49
52
|
version: 5.0.7
|
@@ -51,6 +54,9 @@ dependencies:
|
|
51
54
|
prerelease: false
|
52
55
|
version_requirements: !ruby/object:Gem::Requirement
|
53
56
|
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '5.0'
|
54
60
|
- - ">="
|
55
61
|
- !ruby/object:Gem::Version
|
56
62
|
version: 5.0.7
|
@@ -58,58 +64,58 @@ dependencies:
|
|
58
64
|
name: bundler
|
59
65
|
requirement: !ruby/object:Gem::Requirement
|
60
66
|
requirements:
|
61
|
-
- - "
|
67
|
+
- - "~>"
|
62
68
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
69
|
+
version: '2.1'
|
64
70
|
type: :development
|
65
71
|
prerelease: false
|
66
72
|
version_requirements: !ruby/object:Gem::Requirement
|
67
73
|
requirements:
|
68
|
-
- - "
|
74
|
+
- - "~>"
|
69
75
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
76
|
+
version: '2.1'
|
71
77
|
- !ruby/object:Gem::Dependency
|
72
78
|
name: rspec
|
73
79
|
requirement: !ruby/object:Gem::Requirement
|
74
80
|
requirements:
|
75
|
-
- - "
|
81
|
+
- - "~>"
|
76
82
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
83
|
+
version: '3.7'
|
78
84
|
type: :development
|
79
85
|
prerelease: false
|
80
86
|
version_requirements: !ruby/object:Gem::Requirement
|
81
87
|
requirements:
|
82
|
-
- - "
|
88
|
+
- - "~>"
|
83
89
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
90
|
+
version: '3.7'
|
85
91
|
- !ruby/object:Gem::Dependency
|
86
92
|
name: tapout
|
87
93
|
requirement: !ruby/object:Gem::Requirement
|
88
94
|
requirements:
|
89
|
-
- - "
|
95
|
+
- - "~>"
|
90
96
|
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
97
|
+
version: '0.4'
|
92
98
|
type: :development
|
93
99
|
prerelease: false
|
94
100
|
version_requirements: !ruby/object:Gem::Requirement
|
95
101
|
requirements:
|
96
|
-
- - "
|
102
|
+
- - "~>"
|
97
103
|
- !ruby/object:Gem::Version
|
98
|
-
version: '0'
|
104
|
+
version: '0.4'
|
99
105
|
- !ruby/object:Gem::Dependency
|
100
106
|
name: rspec-ontap
|
101
107
|
requirement: !ruby/object:Gem::Requirement
|
102
108
|
requirements:
|
103
|
-
- - "
|
109
|
+
- - "~>"
|
104
110
|
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
111
|
+
version: '0.3'
|
106
112
|
type: :development
|
107
113
|
prerelease: false
|
108
114
|
version_requirements: !ruby/object:Gem::Requirement
|
109
115
|
requirements:
|
110
|
-
- - "
|
116
|
+
- - "~>"
|
111
117
|
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
118
|
+
version: '0.3'
|
113
119
|
description: Biran is the guy that will help you generate config files for your rail
|
114
120
|
app.
|
115
121
|
email:
|
@@ -121,12 +127,15 @@ files:
|
|
121
127
|
- MIT-LICENSE
|
122
128
|
- README.md
|
123
129
|
- Rakefile
|
130
|
+
- config/_my_config.yml.erb
|
131
|
+
- config/app_config.yml
|
124
132
|
- lib/biran.rb
|
125
133
|
- lib/biran/config.rb
|
126
134
|
- lib/biran/config_defaults.rb
|
127
135
|
- lib/biran/configurinator.rb
|
128
136
|
- lib/biran/configurinator.rb.test_changes
|
129
137
|
- lib/biran/erb_config.rb
|
138
|
+
- lib/biran/exceptions.rb
|
130
139
|
- lib/biran/hash_refinement.rb
|
131
140
|
- lib/biran/railtie.rb
|
132
141
|
- lib/biran/version.rb
|
@@ -134,8 +143,9 @@ files:
|
|
134
143
|
homepage: https://github.com/amco/biran
|
135
144
|
licenses:
|
136
145
|
- MIT
|
137
|
-
metadata:
|
138
|
-
|
146
|
+
metadata:
|
147
|
+
rubygems_mfa_required: 'true'
|
148
|
+
post_install_message:
|
139
149
|
rdoc_options: []
|
140
150
|
require_paths:
|
141
151
|
- lib
|
@@ -150,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
160
|
- !ruby/object:Gem::Version
|
151
161
|
version: '0'
|
152
162
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
154
|
-
signing_key:
|
163
|
+
rubygems_version: 3.2.3
|
164
|
+
signing_key:
|
155
165
|
specification_version: 4
|
156
166
|
summary: Helper for generating config generate tasks.
|
157
167
|
test_files: []
|