biran 0.1.14 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 724bb696cb3fefd277f0d8c892eab6a3bb247fe2cf8015fc721c9d79f5c3fc78
4
- data.tar.gz: 00af99015b69fa0d49f5ebd4f67fa237729416a1ae9aacbf81bb0bd1aab54482
3
+ metadata.gz: d862a844d5e11a1453aad13df8c47fdca3392f8bc64fb82bd726f4eb034630db
4
+ data.tar.gz: 49a1b2185ca65594fa706ebd26c3cfec620db033a12b3763b9eb6944077c77c8
5
5
  SHA512:
6
- metadata.gz: 4613fff5623383163a13cb4592c4b869efbdd0ac08b81494f0e6db4e80ef8356d44ff538dcd03b09df873bff1484010fbd093f045f436d4c19d9e6ec6e4806eb
7
- data.tar.gz: 45744b7d551dbd3f3df0d841fc9fcf8de8cda94fdafae3c20a05545e3b708acde2cb9378fbf69dc39ad149dcc2369c174e53834947c7c55088cec4d9f6a75f17
6
+ metadata.gz: 46bbd0b7e003fe6e5bfd9036a0fb7a9b6c240ebf0b4b0a32d008b8c20a8a140f325cca9e5f8f4bc4706d21627cc646cf65cbf1f75bb3fc431ed8eeea4e738d82
7
+ data.tar.gz: 9209c6ca4a45d8939c0f7b8796a2079a35985afaed20750a6c9bc7d7548e1b4c10f387beb4fd92455f9af0c8413f96c643647582ab59aadf659307079124fc2d
data/README.md CHANGED
@@ -40,7 +40,8 @@ Dir.glob('lib/tasks/*.rake').each {|r| import r}
40
40
  # Configuration
41
41
 
42
42
  You can set where your config files are, rails end and other stuff in a file like `config/initializers/biran.rb`
43
- You can also set options in `config/app_config.yml` in the `app` block. This list will be loaded last and override anything set in the initializer.
43
+ You can also set options in `config/app_config.yml` in the `app` block. This list will be loaded last and override anything set in the initializer. All string
44
+ input is sanitized to remove special characters that don't play well with file system paths. Any special haracters found are replaced with a '-'.
44
45
 
45
46
  Config file example:
46
47
  ```
@@ -92,6 +93,7 @@ the list of things you can configure are:
92
93
  :local_config_filename,
93
94
  :db_config_file_name,
94
95
  :secrets_filename,
96
+ :extra_config_suffix,
95
97
  :config_dirname,
96
98
  :base_path,
97
99
  :shared_dir,
@@ -145,6 +147,16 @@ Available in: config file, initializer**
145
147
 
146
148
  Generally no need to change, but here in case you want to. Default is `secrets.yml`
147
149
 
150
+ ### extra_config_suffix
151
+ **Type: string
152
+ Default: extras
153
+ Available in: environment variable, config_file, initializer**
154
+
155
+ Sets the suffix to be applied to an extra config file you may want to load. The suffix is appended to the value of the config_filename. The default value will be `app_config_extras.yml`.
156
+ This file gets loaded just before the local config file and can be used to provide additional configuration based stored in a second file. There are times when you may want to organize the
157
+ configuration based on sub grouping that the yaml just doesn't allow easily.
158
+ Use cases might include grouping config based on a location, type of host, or even for testing purposes.
159
+
148
160
  ### config_dirname
149
161
  **Type: string
150
162
  Default: config
data/Rakefile CHANGED
@@ -22,10 +22,10 @@ begin
22
22
  task("spec").clear
23
23
 
24
24
  RSpec::Core::RakeTask.new(:spec) do |t|
25
- t.rspec_opts = "--format RSpec::TapY | tapout runtime"
25
+ t.rspec_opts = "--format documentation"
26
26
  end
27
27
 
28
- task :default => :spec
28
+ task default: :spec
29
29
  rescue LoadError
30
30
  raise 'No rspec available'
31
31
  end
@@ -7,9 +7,11 @@ defaults: &defaults
7
7
  extension: '.yml'
8
8
  my_first_value: 1
9
9
  my_second_value: 2
10
+ my_fifth_value: 5
10
11
  nested_values: &nested_defaults
11
12
  my_third_value: 3
12
13
  my_fourth_value: 4
14
+ my_sixth_value: 6
13
15
 
14
16
  test:
15
17
  <<: *defaults
@@ -0,0 +1,10 @@
1
+ defaults: &defaults
2
+ my_fifth_value: 55
3
+ nested_values:
4
+ my_sixth_value: 66
5
+
6
+ development:
7
+ <<: *defaults
8
+
9
+ test:
10
+ <<: *defaults
data/lib/biran/config.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'singleton'
2
3
 
3
4
  module Biran
@@ -6,14 +7,15 @@ module Biran
6
7
 
7
8
  attr_writer :config_filename, :local_config_filename, :db_config_filename,
8
9
  :secrets_filename, :config_dirname, :use_capistrano, :db_config,
9
- :secrets, :base_path, :app_env, :base_dir, :bindings, :app_setup_blocks
10
+ :secrets, :base_path, :app_env, :base_dir, :bindings, :app_setup_blocks,
11
+ :extra_config_suffix
10
12
 
11
13
  attr_accessor :shared_dir
12
14
 
13
15
  def app_env
14
16
  return @app_env if @app_env
15
17
  @app_env = Rails.env if defined? Rails
16
- @app_env ||= 'development'.freeze
18
+ @app_env ||= 'development'
17
19
  end
18
20
 
19
21
  def base_dir
@@ -21,27 +23,27 @@ module Biran
21
23
  end
22
24
 
23
25
  def config_filename
24
- @config_filename ||= 'app_config.yml'.freeze
26
+ @config_filename ||= 'app_config.yml'
25
27
  end
26
28
 
27
29
  def local_config_filename
28
- @local_config_filename ||= 'local_config.yml'.freeze
30
+ @local_config_filename ||= 'local_config.yml'
29
31
  end
30
32
 
31
33
  def db_config_filename
32
- @db_config_filename ||= 'db_config.yml'.freeze
34
+ @db_config_filename ||= 'db_config.yml'
33
35
  end
34
36
 
35
37
  def secrets_filename
36
- @secrets_filename ||= 'secrets.yml'.freeze
38
+ @secrets_filename ||= 'secrets.yml'
37
39
  end
38
40
 
39
41
  def config_dirname
40
- @config_dirname ||= 'config'.freeze
42
+ @config_dirname ||= 'config'
41
43
  end
42
44
 
43
45
  def vhost_public_dirname
44
- @vhost_public_dirname ||= 'public'.freeze
46
+ @vhost_public_dirname ||= 'public'
45
47
  end
46
48
 
47
49
  def use_capistrano
@@ -63,13 +65,17 @@ module Biran
63
65
  end
64
66
 
65
67
  def app_setup_blocks
66
- @app_setup_blocks ||= %i[app].freeze
68
+ @app_setup_blocks ||= %i[app]
67
69
  end
68
70
 
69
71
  def bindings
70
72
  @bindings ||= %i[db_config]
71
73
  end
72
74
 
75
+ def extra_config_suffix
76
+ @extra_config_suffix ||= 'extras'
77
+ end
78
+
73
79
  def base_path
74
80
  return @base_path if @base_path
75
81
  @base_path = Rails.root if defined? Rails
@@ -20,7 +20,8 @@ module Biran
20
20
  end
21
21
 
22
22
  def app_env
23
- ENV['BIRAN_APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || configuration.app_env
23
+ app_env = ENV['BIRAN_APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || configuration.app_env
24
+ sanitize_input(app_env)
24
25
  end
25
26
 
26
27
  def app_base
@@ -41,37 +42,62 @@ module Biran
41
42
  app_config_defaults[:app][:bindings]
42
43
  end
43
44
 
45
+ def config_dirname
46
+ sanitize_input(configuration.config_dirname)
47
+ end
48
+
44
49
  def config_dir
45
- File.join configuration.base_path, configuration.config_dirname
50
+ File.join(configuration.base_path, config_dirname)
46
51
  end
47
52
 
48
53
  def local_config_file
49
54
  ENV['BIRAN_LOCAL_CONFIG_FILE'] ||
50
- File.join(app_shared_dir, configuration.config_dirname, local_config_filename)
55
+ File.join(app_shared_dir, config_dirname, local_config_filename)
51
56
  end
52
57
 
53
58
  def local_config_filename
54
- ENV['BIRAN_LOCAL_CONFIG_FILENAME'] || app_config_defaults[:app][:local_config_filename] || configuration.local_config_filename
59
+ filename= ENV['BIRAN_LOCAL_CONFIG_FILENAME'] || app_config_defaults[:app][:local_config_filename] || configuration.local_config_filename
60
+ sanitize_input( filename )
61
+ end
62
+
63
+ def extra_config_suffix
64
+ suffix = ENV['BIRAN_EXTRA_CONFIG_SUFFIX'] || app_config_defaults[:app][:extra_config_suffix] || configuration.extra_config_suffix
65
+ sanitize_input( suffix )
66
+ end
67
+
68
+ def extra_config_file
69
+ File.join(config_dirname, app_config_filename.gsub(/\.yml$/, "_#{extra_config_suffix}.yml"))
70
+ end
71
+
72
+ def app_config_filename
73
+ sanitize_input(configuration.config_filename)
74
+ end
75
+
76
+ def app_config_file
77
+ File.join(config_dirname, app_config_filename)
55
78
  end
56
79
 
57
80
  def vhost_public_dirname
58
- ENV['BIRAN_VHOST_PUBLIC_DIRNAME'] || app_config_defaults[:app][:vhost_public_dirname]
81
+ pub_dir_name = ENV['BIRAN_VHOST_PUBLIC_DIRNAME'] || app_config_defaults[:app][:vhost_public_dirname]
82
+ sanitize_input(pub_dir_name)
59
83
  end
60
84
 
61
85
  def db_config_override_file
62
- File.join(app_shared_dir, configuration.config_dirname, db_config_filename)
86
+ File.join(app_shared_dir, config_dirname, db_config_filename)
63
87
  end
64
88
 
65
89
  def db_config_filename
66
- app_config_defaults[:app][:db_config_filename] || configuration.db_config_filename
90
+ filename = app_config_defaults[:app][:db_config_filename] || configuration.db_config_filename
91
+ sanitize_input(filename)
67
92
  end
68
93
 
69
94
  def secrets_file
70
- File.join(configuration.base_path, configuration.config_dirname, secrets_filename)
95
+ File.join(configuration.base_path, config_dirname, secrets_filename)
71
96
  end
72
97
 
73
98
  def secrets_filename
74
- app_config_defaults[:app][:secrets_filename] || configuration.secrets_filename
99
+ filename = app_config_defaults[:app][:secrets_filename] || configuration.secrets_filename
100
+ sanitize_input(filename)
75
101
  end
76
102
 
77
103
  def default_db_config_file
@@ -81,5 +107,10 @@ module Biran
81
107
  def use_capistrano?
82
108
  # Implement in consumer class
83
109
  end
110
+
111
+ def sanitize_input string
112
+ # Borrowed from ActiveStorage
113
+ string.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
114
+ end
84
115
  end
85
116
  end
@@ -61,6 +61,7 @@ module Biran
61
61
  app_config[:secrets].deep_merge! get_secrets_content(app_config[:secrets_file_path])
62
62
  app_config[:db_config].deep_merge! build_db_config
63
63
 
64
+ app_config.deep_merge! extra_config_file_contents
64
65
  app_config.deep_merge! local_config_file_contents
65
66
  end
66
67
 
@@ -72,13 +73,12 @@ module Biran
72
73
 
73
74
  def base_db_config
74
75
  return @base_db_config if @base_db_config
75
- return @base_db_config = {} unless File.exists? default_db_config_file
76
+ return @base_db_config = {} unless File.exist? default_db_config_file
76
77
  @base_db_config ||= process_config_file(default_db_config_file)
77
78
  end
78
79
 
79
80
  def app_config_defaults
80
81
  return @app_config_defaults if @app_config_defaults
81
- app_config_file = File.join(configuration.config_dirname, configuration.config_filename)
82
82
  app_defaults = app_defaults_init.dup
83
83
  config_properties = process_config_file(app_config_file)
84
84
  @app_config_defaults = app_defaults.deep_merge! config_properties
@@ -104,15 +104,21 @@ module Biran
104
104
 
105
105
  def local_config_file_contents
106
106
  return @local_config_contents if @local_config_contents
107
- return @local_config_conents = {} unless File.exists? local_config_file
107
+ return @local_config_conents = {} unless File.exist? local_config_file
108
108
  @local_config_contents = process_config_file(local_config_file)
109
109
  end
110
110
 
111
111
  def get_secrets_content(secrets_file)
112
- return {} unless File.exists? secrets_file
112
+ return {} unless File.exist? secrets_file
113
113
  process_config_file secrets_file
114
114
  end
115
115
 
116
+ def extra_config_file_contents
117
+ return @extra_config_contents if @extra_config_contents
118
+ return @extra_config_contents = {} unless File.exist? extra_config_file
119
+ @extra_config_contents = process_config_file(extra_config_file)
120
+ end
121
+
116
122
  def sanitize_config_files files_list
117
123
  lambda do |(file, _)|
118
124
  files_list[file] ||= {extension: ''}
@@ -124,7 +130,6 @@ module Biran
124
130
 
125
131
  def yaml_load data_content
126
132
  # 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
133
  YAML.safe_load(data_content, aliases: true)
129
134
  end
130
135
 
@@ -41,7 +41,7 @@ module Biran
41
41
 
42
42
  def process_erb
43
43
  config_erb_file = File.join(source_dir, "_#{name}#{extension}.erb")
44
- ERB.new(File.read(config_erb_file), nil, '-')
44
+ ERB.new(File.read(config_erb_file), trim_mode: '-')
45
45
  rescue Errno::ENOENT
46
46
  raise Biran::ConfigSyntaxError, "Missing template file for #{name}: #{config_erb_file}"
47
47
  end
data/lib/biran/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Biran
2
- VERSION = '0.1.14'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - javierg
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-01 00:00:00.000000000 Z
13
+ date: 2023-11-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -89,33 +89,19 @@ dependencies:
89
89
  - !ruby/object:Gem::Version
90
90
  version: '3.7'
91
91
  - !ruby/object:Gem::Dependency
92
- name: tapout
92
+ name: nokogiri
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.4'
97
+ version: '1.15'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.4'
105
- - !ruby/object:Gem::Dependency
106
- name: rspec-ontap
107
- requirement: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '0.3'
112
- type: :development
113
- prerelease: false
114
- version_requirements: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: '0.3'
104
+ version: '1.15'
119
105
  description: Biran is the guy that will help you generate config files for your rail
120
106
  app.
121
107
  email:
@@ -129,6 +115,7 @@ files:
129
115
  - Rakefile
130
116
  - config/_my_config.yml.erb
131
117
  - config/app_config.yml
118
+ - config/app_config_test.yml
132
119
  - lib/biran.rb
133
120
  - lib/biran/config.rb
134
121
  - lib/biran/config_defaults.rb
@@ -153,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
140
  requirements:
154
141
  - - ">="
155
142
  - !ruby/object:Gem::Version
156
- version: '0'
143
+ version: 2.7.0
157
144
  required_rubygems_version: !ruby/object:Gem::Requirement
158
145
  requirements:
159
146
  - - ">="