benry-config 0.1.0 → 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
- SHA1:
3
- metadata.gz: 3370f1b72911ca0f9a74d6240b1025a792166d3d
4
- data.tar.gz: a4b2152cb0e4f51f4b3c36e25fccd66bf210f5e3
2
+ SHA256:
3
+ metadata.gz: 29ac681e125266660c141ed00cd5c1d8b1667a2769b89810a4747ea5d0fa144b
4
+ data.tar.gz: 619ca8af95d35aebe618c2b87e8438bbaf7300658a4fdf8dac62705946b759a4
5
5
  SHA512:
6
- metadata.gz: 7f81be992cc07abe26b2680940cf618daa2f5f4047ac91748e3ad16286d54d6c64a527a543e68e2fa50bcd7114307d3dfb4ac202d977b54ad5720651db3a3913
7
- data.tar.gz: 1939f9f82a48c679ae927ea9f34f0e34d75bfb08e3909984b6e68a07267fb24f959a2a588e8bf2210a4721a96efef152bde1ebd4636089708b691d5e7b213021
6
+ metadata.gz: 45113ff1e524a0c92053e30488c8963e64ea0b87b941cd44ffdb1fd93e7f3a76a2e24fa8b75348260c851577c7398aa5eef16408b4e4c6ee2db47c28c1b508fd
7
+ data.tar.gz: 36a644e4fb0f053bda69836abca724470a212743a7bbfd297fbe2c50b50114ba6d7b7ae1d2240923b36a310705f7466adec260e48c9ebf33431926d762b5792f
data/CHANGES.md ADDED
@@ -0,0 +1,19 @@
1
+ CHANGES
2
+ =======
3
+
4
+
5
+ Release 0.2.0 (2023-10-11)
6
+ --------------------------
7
+
8
+ * [change] Rename 'Benry::BaseConfig' class to 'Benry::Config' class. (Old name is still available for compatibility.)
9
+ * [enhance] Add `SECRET` which represents secret value.
10
+ * [enhance] Enhance `ABSTRACT` to support `ABSTRACT['NAME']` style setting.
11
+ * [enhance] Define `#defined?()` in `Benry::Config` class.
12
+ * [enhance] Define `#each()` and `#each!()` in `Benry::Config` class.
13
+ * [chnage] Switch unit test library from MiniTest to Oktest.
14
+
15
+
16
+ Release 0.1.0 (2016-09-04)
17
+ --------------------------
18
+
19
+ * First public release.
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 kuwata-lab.com
3
+ Copyright (c) 2016 kwatch@gmail.com
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,65 +1,128 @@
1
- benry-config
2
- ============
1
+ # Benry-Config
3
2
 
4
- ($Release: 0.1.0 $)
3
+ ($Release: 0.2.0 $)
5
4
 
6
5
 
7
- Overview
8
- --------
6
+ ## What's this?
9
7
 
10
8
  Utility class to support configuration.
11
9
 
10
+ Features:
11
+
12
12
  * Easy to define configuration for environments (production, development, ...).
13
13
  * Raises error when configuration name is wrong (typo).
14
- * Represents secret configurations which should be set in private file.
14
+ * Represents secret configurations which should be set by environment var or in secret file.
15
+
16
+ Links:
17
+
18
+ * Document: <https://kwatch.github.io/benry-ruby/benry-config.html>
19
+ * GitHub: <https://github.com/kwatch/benry-ruby/tree/main/benry-config>
20
+ * Changes: <https://github.com/kwatch/benry-ruby/tree/main/benry-config/CHANGES.md>
21
+
22
+
23
+
24
+ ### Table of Contents
25
+
26
+ <!-- TOC -->
27
+
28
+ * [What's this?](#whats-this)
29
+ * [Example](#example)
30
+ * [Copyright and License](#copyright-and-license)
15
31
 
32
+ <!-- /TOC -->
16
33
 
17
- Example
18
- -------
34
+
35
+
36
+ ## Example
37
+
38
+ File: config/app.rb
19
39
 
20
40
  ```ruby
21
- #----- config/common.rb -----
22
41
  require 'benry/config'
23
- class CommonConfig < Benry::BaseConfig
24
- add :db_user , "user1"
25
- add :db_pass , ABSTRACT
26
- add :session_cooie , "sess"
27
- add :session_secret , SECRET
42
+
43
+ class AppConfigBase < Benry::Config
44
+ ## add names and values
45
+ add :db_host , "localhost"
46
+ add :db_user , "user1"
47
+ add :db_pass , ABSTRACT # should be set value in subclass
48
+ add :session_cookie , "sess"
49
+ add :session_secret , SECRET
50
+ ## or:
51
+ #add :db_pass , ABSTRACT['DB_PASS'] # get value from ENV
52
+ #add :session_secret , SECRET['SESS_SECRET'] # get secret value from ENV
53
+ end
54
+ ```
55
+
56
+ File: config/app_dev.rb (for development environment)
57
+
58
+ ```ruby
59
+ require_relative './app'
60
+
61
+ ## for development environment
62
+ class AppConfig < AppConfigBase
63
+ ## set (= override) existing values
64
+ set :db_pass , "pass1" # set ABSTRACT value
28
65
  end
66
+ ```
67
+
68
+ File: config/app_prod.rb (for production environment)
29
69
 
30
- #----- config/development.rb -----
31
- require 'config/common'
32
- class Config < CommonConfig
33
- set :db_pass , "pass1"
70
+ ```ruby
71
+ require_relative './app'
72
+
73
+ ## for production environment
74
+ class AppConfig < AppConfigBase
75
+ ## set (= override) existing values
76
+ set :db_host , "db-master" # override existing value
77
+ set :db_pass , "passXXX" # set ABSTRACT value
78
+ ## error because `:db_name` is not defined in paremnt class.
79
+ set :db_name , "prod1" #=> Benry::ConfigError (not defined)
34
80
  end
81
+ ```
82
+
83
+ File: config/app.secret (should be ignored by `.gitignore`)
35
84
 
36
- #----- config/development.private -----
37
- Config.class_eval do
38
- set :session_secret , "abc123"
85
+ ```ruby
86
+ ## this file should be ignored by '.gitignore', and
87
+ ## file permission should be `600`.
88
+ AppConfig.class_eval do
89
+ set :session_secret , "YRjCIAiPlCBvwLUq5mnZ" # set SECRET value
39
90
  end
91
+ ```
40
92
 
41
- #----- main.rb -----
42
- ## Ruby < 2.2 has obsoleted 'Config' class, therefore remove it at first.
43
- Object.class_eval { remove_const :Config } if defined?(Config)
44
- #
45
- rack_env = ENV['RACK_ENV'] or raise "$RACK_ENV required."
46
- require "./config/#{rack_env}.rb"
47
- load "./config/#{rack_env}.private"
93
+ File: main.rb
94
+
95
+ ```ruby
96
+ ## load config files
97
+ app_env = ENV['APP_ENV'] or raise "$APP_ENV required."
98
+ require "./config/app.rb" # define AppConfigBase class
99
+ require "./config/app_#{app_env}.rb" # define AppConfig class
100
+ load "./config/app.secret" # modify AppConfig class
101
+ ## or:
102
+ #load "./config/app.#{app_env}.secret"
103
+
104
+ ## create a config object
105
+ $config = AppConfig.new.freeze
48
106
  #
49
- $config = Config.new.freeze
50
107
  p $config.db_user #=> "user1"
51
108
  p $config.db_pass #=> "pass1"
52
109
  p $config.session_cookie #=> "sess"
53
- p $config.session_secret #=> "abc123"
110
+ p $config.session_secret #=> "YRjCIAiPlCBvwLUq5mnZ"
111
+ #
112
+ p $config.defined?(:db_user) #=> true
113
+ p $config.defined?(:db_pass) #=> true
114
+ p $config.defined?(:db_name) #=> false
115
+ #
116
+ p $config.get_all(:db_) #=> {:host=>"localhost", :user=>"user1", :pass=>"pass1"}
117
+ p $config.get_all(:session_) #=> {:cookie=>"sess", :secret=>"YRjCIAiPlCBvwLUq5mnZ"}
54
118
  #
55
- p $config.get_all(:db_) #=> {:user=>"user1", :pass=>"pass1"}
56
- p $config.get_all(:session_) #=> {:cookie=>"sess", :secret=>"abc123"}
119
+ $config.each {|k, v| puts "#{k}=#{v.inspect}" } # hide secret values as "(secret)"
120
+ $config.each! {|k, v| puts "#{k}=#{v.inspect}" } # not hide secret values
57
121
  ```
58
122
 
59
123
 
60
- Copyright and License
61
- ---------------------
62
124
 
63
- $Copyright: copyright(c) 2016 kuwata-lab.com all rights reserved $
125
+ ## Copyright and License
64
126
 
65
- $License: MIT License $
127
+ * $Copyright: copyright(c) 2016 kwatch@gmail.com $
128
+ * $License: MIT License $
data/Rakefile.rb ADDED
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ PROJECT = "benry-config"
5
+ RELEASE = ENV['RELEASE'] || "0.0.0"
6
+ COPYRIGHT = "copyright(c) 2016 kwatch@gmail.com"
7
+ LICENSE = "MIT License"
8
+
9
+ README_DESTDIR = "examples"
10
+
11
+ Dir.glob('./task/*-task.rb').sort.each {|x| require x }
12
+
13
+ desc "retrieve example code from README"
14
+ task :examples => "readme:retrieve"
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "benry-config"
5
+ spec.version = "$Release: 0.2.0 $".split()[1]
6
+ spec.author = "kwatch"
7
+ spec.email = "kwatch@gmail.com"
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.homepage = "https://kwatch.github.io/benry-ruby/benry-config.html"
10
+ spec.summary = "Application configuration library"
11
+ spec.description = <<"END"
12
+ Small library for configuration of application.
13
+
14
+ See #{spec.homepage} for details.
15
+ END
16
+ spec.license = "MIT"
17
+ spec.files = Dir[
18
+ "README.md", "MIT-LICENSE", "CHANGES.md",
19
+ "Rakefile.rb", "#{spec.name}.gemspec",
20
+ "lib/**/*.rb", "test/**/*_test.rb", "task/**/*.rb",
21
+ "examples/**/*.*", #"bin/*",
22
+ "doc/*.html", "doc/css/*",
23
+ ]
24
+ #spec.executables = []
25
+ spec.bindir = "bin"
26
+ spec.require_path = "lib"
27
+ spec.test_files = Dir["test/**/*_test.rb"] # or: ["test/run_all.rb"]
28
+ #spec.extra_rdoc_files = ["README.md", "CHANGES.md"]
29
+
30
+ spec.required_ruby_version = ">= 2.3"
31
+ spec.add_development_dependency "oktest" , "~> 1"
32
+ end
@@ -0,0 +1,139 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1"/>
6
+ <meta name="description" content="">
7
+ <meta name="theme-color" content="#fafafa">
8
+ <meta property="og:title" content="">
9
+ <meta property="og:type" content="">
10
+ <meta property="og:url" content="">
11
+ <meta property="og:image" content="">
12
+ <title></title>
13
+ <link rel="stylesheet" href="lib/sanitize.css/2.0.0/sanitize.min.css">
14
+ <link rel="stylesheet" href="css/style.css">
15
+ </head>
16
+ <body>
17
+ <main>
18
+ <section class="chapter" id="benry-config">
19
+ <h1>Benry-Config</h1>
20
+ <nav class="nav">
21
+ <ul class="nav">
22
+ </ul>
23
+ </nav>
24
+ <p>($Release: 0.2.0 $)</p>
25
+ <section class="section" id="whats-this">
26
+ <h2>What's this?</h2>
27
+ <p>Utility class to support configuration.</p>
28
+ <p>Features:</p>
29
+ <ul>
30
+ <li>Easy to define configuration for environments (production, development, ...).</li>
31
+ <li>Raises error when configuration name is wrong (typo).</li>
32
+ <li>Represents secret configurations which should be set by environment var or in secret file.</li>
33
+ </ul>
34
+ <p>Links:</p>
35
+ <ul>
36
+ <li>Document: <a href="https://kwatch.github.io/benry-ruby/benry-config.html">https://kwatch.github.io/benry-ruby/benry-config.html</a></li>
37
+ <li>GitHub: <a href="https://github.com/kwatch/benry-ruby/tree/main/benry-config">https://github.com/kwatch/benry-ruby/tree/main/benry-config</a></li>
38
+ <li>Changes: <a href="https://github.com/kwatch/benry-ruby/tree/main/benry-config/CHANGES.md">https://github.com/kwatch/benry-ruby/tree/main/benry-config/CHANGES.md</a></li>
39
+ </ul>
40
+ <section class="subsection" id="table-of-contents">
41
+ <h3>Table of Contents</h3>
42
+ <div class="toc">
43
+ <ul>
44
+ <li><a href="#whats-this">What's this?</a></li>
45
+ <li><a href="#example">Example</a></li>
46
+ <li><a href="#copyright-and-license">Copyright and License</a></li>
47
+ </ul>
48
+ </div>
49
+ </section>
50
+ </section>
51
+ <section class="section" id="example">
52
+ <h2>Example</h2>
53
+ <p>File: config/app.rb</p>
54
+ <pre class="language-ruby">
55
+ <strong>require 'benry/config'</strong>
56
+
57
+ <strong>class AppConfigBase &lt Benry::Config</strong>
58
+ ## add names and values
59
+ <strong>add</strong> :db_host , "localhost"
60
+ <strong>add</strong> :db_user , "user1"
61
+ <strong>add</strong> :db_pass , <strong>ABSTRACT</strong> # should be set value in subclass
62
+ <strong>add</strong> :session_cookie , "sess"
63
+ <strong>add</strong> :session_secret , <strong>SECRET</strong>
64
+ ## or:
65
+ #add :db_pass , <strong>ABSTRACT['DB_PASS']</strong> # get value from ENV
66
+ #add :session_secret , <strong>SECRET['SESS_SECRET']</strong> # get secret value from ENV
67
+ end
68
+ </pre>
69
+ <p>File: config/app_dev.rb (for development environment)</p>
70
+ <pre class="language-ruby">
71
+ require_relative './app'
72
+
73
+ ## for development environment
74
+ <strong>class AppConfig &lt AppConfigBase</strong>
75
+ ## set (= override) existing values
76
+ <strong>set</strong> :db_pass , "pass1" # set ABSTRACT value
77
+ end
78
+ </pre>
79
+ <p>File: config/app_prod.rb (for production environment)</p>
80
+ <pre class="language-ruby">
81
+ require_relative './app'
82
+
83
+ ## for production environment
84
+ <strong>class AppConfig &lt AppConfigBase</strong>
85
+ ## set (= override) existing values
86
+ <strong>set</strong> :db_host , "db-master" # override existing value
87
+ <strong>set</strong> :db_pass , "passXXX" # set ABSTRACT value
88
+ ## error because `:db_name` is not defined in paremnt class.
89
+ <strong>set</strong> :db_name , "prod1" #=&gt; <strong>Benry::ConfigError (not defined)</strong>
90
+ end
91
+ </pre>
92
+ <p>File: config/app.secret (should be ignored by `.gitignore`)</p>
93
+ <pre class="language-ruby">
94
+ ## this file should be ignored by '.gitignore', and
95
+ ## file permission should be `600`.
96
+ <strong>AppConfig.class_eval do</strong>
97
+ <strong>set</strong> :session_secret , "YRjCIAiPlCBvwLUq5mnZ" # set SECRET value
98
+ end
99
+ </pre>
100
+ <p>File: main.rb</p>
101
+ <pre class="language-ruby">
102
+ ## load config files
103
+ app_env = ENV['APP_ENV'] or raise "$APP_ENV required."
104
+ <strong>require "./config/app.rb"</strong> # define AppConfigBase class
105
+ <strong>require "./config/app_#{app_env}.rb"</strong> # define AppConfig class
106
+ <strong>load "./config/app.secret"</strong> # modify AppConfig class
107
+ ## or:
108
+ #load "./config/app.#{app_env}.secret"
109
+
110
+ ## create a config object
111
+ <strong>$config = AppConfig.new.freeze</strong>
112
+ #
113
+ p $config.db_user #=&gt; "user1"
114
+ p $config.db_pass #=&gt; "pass1"
115
+ p $config.session_cookie #=&gt; "sess"
116
+ p $config.session_secret #=&gt; "YRjCIAiPlCBvwLUq5mnZ"
117
+ #
118
+ p <strong>$config.defined?</strong>(:db_user) #=&gt; true
119
+ p <strong>$config.defined?</strong>(:db_pass) #=&gt; true
120
+ p <strong>$config.defined?</strong>(:db_name) #=&gt; false
121
+ #
122
+ p <strong>$config.get_all(:db_)</strong> #=&gt; {:host=&gt;"localhost", :user=&gt;"user1", :pass=&gt;"pass1"}
123
+ p <strong>$config.get_all(:session_)</strong> #=&gt; {:cookie=&gt;"sess", :secret=&gt;"YRjCIAiPlCBvwLUq5mnZ"}
124
+ #
125
+ <strong>$config.each</strong> {|k, v| puts "#{k}=#{v.inspect}" } # hide secret values as "(secret)"
126
+ <strong>$config.each!</strong> {|k, v| puts "#{k}=#{v.inspect}" } # not hide secret values
127
+ </pre>
128
+ </section>
129
+ <section class="section" id="copyright-and-license">
130
+ <h2>Copyright and License</h2>
131
+ <ul>
132
+ <li>$Copyright: copyright(c) 2016 kwatch@gmail.com $</li>
133
+ <li>$License: MIT License $</li>
134
+ </ul>
135
+ </section>
136
+ </section>
137
+ </main>
138
+ </body>
139
+ </html>
data/doc/css/style.css ADDED
@@ -0,0 +1,168 @@
1
+ @charset "UTF-8";
2
+
3
+ body {
4
+ font-family: "Helvetica Neue",Arial,"Hiragino Kaku Gothic ProN","Hiragino Sans",Meiryo,sans-serif;
5
+ color: #333;
6
+ line-height: 1.42857143;
7
+ background: #eef0f6;
8
+ margin-top: 0;
9
+ }
10
+ main {
11
+ max-width: 830px;
12
+ margin: 0 auto;
13
+ font-size: 16px;
14
+ color: #999;
15
+ }
16
+
17
+
18
+ h1 {
19
+ text-align: center;
20
+ margin: 0 0 30px 0;
21
+ padding: 50px 0 30px 0;
22
+ background: #39c;
23
+ color: #fff;
24
+ font-weight: normal;
25
+ font-size: 280%;
26
+ border-radius: 0 0 10px 10px;
27
+ }
28
+ h2 {
29
+ border: solid 0px #39c;
30
+ border-width: 0 0 0 15px;
31
+ padding: 20px 0 10px 15px;
32
+ font-size: 200%;
33
+ font-weight: normal;
34
+ color: #39c;
35
+ margin: 0 0 20px 0;
36
+ }
37
+ h3 {
38
+ color: #39c;
39
+ margin-top: 30px;
40
+ font-size: 180%;
41
+ font-weight: normal;
42
+ }
43
+ h2 > code, h3 > code {
44
+ color: #39c;
45
+ font-weight: bold;
46
+ }
47
+
48
+
49
+ section.section {
50
+ background: #fff;
51
+ border-radius: 10px;
52
+ padding: 30px 15px 30px 15px;
53
+ color: #333;
54
+ margin: 30px 0 30px 0;
55
+ }
56
+ section.subsection {
57
+ margin-top: 60px;
58
+ }
59
+
60
+
61
+ pre, code, kbd, var, samp {
62
+ font-family: 'Courier New',Courier,Menlo,Monaco,Consolas,Meiryo,monospace,monospace;
63
+ }
64
+ pre {
65
+ border: solid 1px #ddd;
66
+ border-radius: 4px;
67
+ background: #eee;
68
+ Xbackground: #f6f6f6;
69
+ padding: 5px 10px;
70
+ color: #444;
71
+ word-break: break-all;
72
+ }
73
+ pre > strong {
74
+ font-weight: bold;
75
+ color: #900;
76
+ }
77
+ pre.language-terminal {
78
+ background: #333;
79
+ color: #fff;
80
+ border-color: #000;
81
+ }
82
+ pre.language-terminal > strong {
83
+ color: #f66;
84
+ }
85
+ code {
86
+ border: solid 1px #e9e9e9;
87
+ border-radius: 2px;
88
+ background: #f6f6f6;
89
+ padding: 1px 3px;
90
+ color: #444;
91
+ }
92
+ h2 > code, h3 > code {
93
+ border: none;
94
+ background-color: transparent;
95
+ }
96
+
97
+
98
+ dt.bold {
99
+ font-weight: bold;
100
+ }
101
+
102
+
103
+ /**
104
+ nav.nav {
105
+ }
106
+ ul.nav {
107
+ padding: 0;
108
+ border: solid 1px #39c;
109
+ border-width: 0 0 6px 0;
110
+ }
111
+ li.nav {
112
+ display: inline-block;
113
+ margin-left: 10px;
114
+ padding: 5px 30px;
115
+ font-size: large;
116
+ Xfont-weight: bold;
117
+ background: #fff;
118
+ border-radius: 5px 5px 0 0;
119
+ border: solid 1px #39c;
120
+ border-width: 1px 1px 0 1px;
121
+ }
122
+ li.nav > a {
123
+ color: #39c;
124
+ text-decoration: none;
125
+ }
126
+ li.nav > a:hover {
127
+ text-decoration: underline;
128
+ }
129
+ li.nav.curr {
130
+ background: #39c;
131
+ }
132
+ li.nav.curr > a {
133
+ color: #fff;
134
+ }
135
+ **/
136
+ nav.nav {
137
+ text-align: center;
138
+ }
139
+ ul.nav {
140
+ padding-left: 0;
141
+ display: inline-block;
142
+ margin: 0;
143
+ font-size: 0;
144
+ }
145
+ li.nav {
146
+ display: inline-block;
147
+ padding: 0 20px;
148
+ border: solid #39c;
149
+ border-width: 0 0 0 1px;
150
+ margin: 0;
151
+ background: #eef0f6;
152
+ }
153
+ li.nav:first-child {
154
+ border-width: 0 0 0 0;
155
+ }
156
+ li.nav > a {
157
+ font-size: large;
158
+ text-decoration: none;
159
+ color: #39c;
160
+ margin: 0;
161
+ }
162
+ li.nav > a:hover {
163
+ text-decoration: underline;
164
+ }
165
+ li.nav.curr > a {
166
+ font-weight: bold;
167
+ text-decoration: underline;
168
+ }
@@ -0,0 +1,13 @@
1
+ require 'benry/config'
2
+
3
+ class AppConfigBase < Benry::Config
4
+ ## add names and values
5
+ add :db_host , "localhost"
6
+ add :db_user , "user1"
7
+ add :db_pass , ABSTRACT # should be set value in subclass
8
+ add :session_cookie , "sess"
9
+ add :session_secret , SECRET
10
+ ## or:
11
+ #add :db_pass , ABSTRACT['DB_PASS'] # get value from ENV
12
+ #add :session_secret , SECRET['SESS_SECRET'] # get secret value from ENV
13
+ end
@@ -0,0 +1,5 @@
1
+ ## this file should be ignored by '.gitignore', and
2
+ ## file permission should be `600`.
3
+ AppConfig.class_eval do
4
+ set :session_secret , "YRjCIAiPlCBvwLUq5mnZ" # set SECRET value
5
+ end
@@ -0,0 +1,7 @@
1
+ require_relative './app'
2
+
3
+ ## for development environment
4
+ class AppConfig < AppConfigBase
5
+ ## set (= override) existing values
6
+ set :db_pass , "pass1" # set ABSTRACT value
7
+ end
@@ -0,0 +1,10 @@
1
+ require_relative './app'
2
+
3
+ ## for production environment
4
+ class AppConfig < AppConfigBase
5
+ ## set (= override) existing values
6
+ set :db_host , "db-master" # override existing value
7
+ set :db_pass , "passXXX" # set ABSTRACT value
8
+ ## error because `:db_name` is not defined in paremnt class.
9
+ set :db_name , "prod1" #=> Benry::ConfigError (not defined)
10
+ end
data/examples/main.rb ADDED
@@ -0,0 +1,25 @@
1
+ ## load config files
2
+ app_env = ENV['APP_ENV'] or raise "$APP_ENV required."
3
+ require "./config/app.rb" # define AppConfigBase class
4
+ require "./config/app_#{app_env}.rb" # define AppConfig class
5
+ load "./config/app.secret" # modify AppConfig class
6
+ ## or:
7
+ #load "./config/app.#{app_env}.secret"
8
+
9
+ ## create a config object
10
+ $config = AppConfig.new.freeze
11
+ #
12
+ p $config.db_user #=> "user1"
13
+ p $config.db_pass #=> "pass1"
14
+ p $config.session_cookie #=> "sess"
15
+ p $config.session_secret #=> "YRjCIAiPlCBvwLUq5mnZ"
16
+ #
17
+ p $config.defined?(:db_user) #=> true
18
+ p $config.defined?(:db_pass) #=> true
19
+ p $config.defined?(:db_name) #=> false
20
+ #
21
+ p $config.get_all(:db_) #=> {:host=>"localhost", :user=>"user1", :pass=>"pass1"}
22
+ p $config.get_all(:session_) #=> {:cookie=>"sess", :secret=>"YRjCIAiPlCBvwLUq5mnZ"}
23
+ #
24
+ $config.each {|k, v| puts "#{k}=#{v.inspect}" } # hide secret values as "(secret)"
25
+ $config.each! {|k, v| puts "#{k}=#{v.inspect}" } # not hide secret values