appconf 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb7352ca6239bfa42d001bcae82df50058bffc31
4
+ data.tar.gz: 86db299e039e5827d83cc00c2e2a9f6d58dd6f07
5
+ SHA512:
6
+ metadata.gz: fe89508179aa1b42c26dc96fae13b96b8ad0ac0dc7d085b6f33be5850c8a569831466d06486c6a8fd1059cd79065261c57ffe155b77a703cecbf5c292ff6f1d7
7
+ data.tar.gz: 61f7bcc7d2fd63645e180ece90bf75377ea586e503ffeebaa938a6e24acca19fce2a4fb07f208b2492980466a20c13f5e0d9ac7f32fa21cc57c12af4ca5af651
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -14,36 +14,40 @@ gem install appconf
14
14
 
15
15
  **AppConf** loads and parses a series of YAML configuration files in priority, which means if multiple configuration items with the same path name exist in different files, then the value of the item in the highest priority file will be selected as query result.
16
16
 
17
- **AppConf** will loads all these YAML configuration files, if exist, in priority highest to lowest:
17
+ After below setup code:
18
+ ```ruby
19
+ AppConfig.setup 'myapp', '/root-dir/of/myapp', '/deployment/dir'
20
+ ```
21
+ **AppConf** will try to load and parse all these YAML configuration files, if exist, in priority highest to lowest:
18
22
 
19
- - *`/path/to/specified/deployment/dir`*/*`myapp`*.*`ruby-platform`*.yaml
20
- - *`/path/to/specified/deployment/dir`*/*`myapp`*.yaml
21
- - *`/home/username`*/*`.myapp`*/*`myapp`*.*`ruby-platform`*.yaml
22
- - *`/home/username`*/*`.myapp`*/*`myapp`*.yaml
23
- - /etc/*`myapp`*/*`myapp`*.*`ruby-platform`*.yaml
24
- - /etc/*`myapp`*/*`myapp`*.yaml
25
- - *`/path/to/myapp`*/conf/*`myapp`*.*`ruby-platform`*.yaml
26
- - *`/path/to/myapp`*/conf/*`myapp`*.yaml
23
+ - `/deployment/dir/myapp.`*ruby-platform*`.config.yaml`
24
+ - `/deployment/dir/myapp.config.yaml`
25
+ - */home/username*`/.myapp/myapp.`*ruby-platform*`.config.yaml`
26
+ - */home/username*`/.myapp/myapp.config.yaml`
27
+ - `/etc/myapp/myapp.`*ruby-platform*`.config.yaml`
28
+ - `/etc/myapp/myapp.config.yaml`
29
+ - `/root-dir/of/myapp/config/myapp.`*ruby-platform*`.config.yaml`
30
+ - `/root-dir/of/myapp/config/myapp.config.yaml`
27
31
 
28
32
  Where:
29
33
 
30
- - *`/path/to/specified/deployment/dir`*: The directory where you app is deployed, use AppConfig::setup to tell the gem where it is.
34
+ - `/deployment/dir/`: The directory where you app is deployed, use AppConfig::setup to tell the gem where it is. When this dir is not specified or is nil, *AppConf* will try to use dir specified by environment variable: *MYAPP*_CONF_DIR. In this case, *MYAPP* part of the environment variable name is the uppercase of first argument value of AppConfig::setup function. If this is still nil, deployment config files will not be used.
31
35
 
32
36
 
33
- - *`myapp`*: The name of the configuration file you requested via AppConfig::get_conf, or the name of your app when nil is used for configuration file name. The app name is setup via AppConfig::setup.
34
- - *`.myapp`*: Note that there is a **dot** before `myapp` for the name of this directory, which holds user level configuration file. While on Windows, there is **no** such dot.
37
+ - `myapp`: The name of the configuration file you requested via AppConfig::get_conf, or the name of your app when nil is used for configuration file name. The app name is setup via AppConfig::setup.
38
+ - `.myapp`: Note that there is a **dot** before `myapp` for the name of this directory, which holds user level configuration file. While on Windows, there is **no** such dot.
35
39
 
36
40
 
37
- - *`ruby-platform`*: The platform of the ruby is running on. For jruby, it is `java`.
41
+ - `ruby-platform`: The platform name (i.e. value of the global variable `RUBY_PLATFORM`) of the ruby is running on. e.g. for jruby, it is `java`.
38
42
 
39
43
 
40
- - *`/home/username`*: The home directory of the user who is running your app. In Windows, it's `ENV['USERPROFILE']`, for POSIX, `ENV['HOME']` is used.
44
+ - `/home/username`: The home directory of the user who is running your app. In Windows, it's `ENV['USERPROFILE']`, for POSIX, `ENV['HOME']` is used.
41
45
 
42
46
 
43
47
  - `/etc`: In Windows, `ENV['ALLUSERSPROFILE']` is used.
44
48
 
45
49
 
46
- - *`/path/to/myapp`*: The root directory where your app resides in.
50
+ - `/root-dir/of/myapp`: The root directory where your app resides in.
47
51
 
48
52
  ## Why YAML?
49
53
 
@@ -51,7 +55,7 @@ XML is heavy and verbose, JSON has no comments, that's it.
51
55
 
52
56
  ## Usage
53
57
 
54
- Say you have a ruby app named `awsome`, need a default configuration file located in `conf` directory under your app's root path, named `awsome.yaml` like this (in YAML):
58
+ Say you have a ruby app named `awsome`, need a default configuration file located in `config` directory under your app's root path, named `awsome.config.yaml` like this (in YAML):
55
59
 
56
60
  ```yaml
57
61
  ---
@@ -60,7 +64,7 @@ db:
60
64
  conection: sqlite://awsome.db
61
65
  ```
62
66
 
63
- While when you are testing you app on your development machine, you want to use a specific sqlite database file located at `/home/arloan/awsome-db/test-2016.db`, how can I do? It's simple, place a file named `awsome.yaml` under `/home/arloan/.awsome/`, with the contents:
67
+ While when you are testing you app on your development machine, you may want to use a specific sqlite database file located at `/home/arloan/awsome-db/test-2016.db`. That is simple, just place a file named `awsome.config.yaml` under `/home/arloan/.awsome/`, with the contents:
64
68
 
65
69
  ```yaml
66
70
  ---
@@ -68,7 +72,7 @@ db:
68
72
  connection: sqlite:///home/arloan/awsome-db/test-2016.db
69
73
  ```
70
74
 
71
- In addition, you want your app to be compatible with jruby, and want to use a different, jruby specific database connection method when running under jruby, then you can create a configuration file named `awsome.java.yaml` and place it along with your default `awsome.yaml`, in `conf` directory under your app's root path, with the contents:
75
+ In addition, you want your app to be compatible with jruby, and want to use a different, jruby specific database connection method when running under jruby, then you can create a configuration file named `awsome.java.config.yaml` and place it along with your default `awsome.config.yaml`, in `config` directory under your app's root path, with the contents:
72
76
 
73
77
  ```yaml
74
78
  ---
@@ -89,7 +93,7 @@ AppConfig.setup 'Awsome', # app name, will be converted to lower case automatica
89
93
  # default config with app name and deployment directory
90
94
  default_config = AppConfig.get_config
91
95
 
92
- # use another series of configuration files with new name, use 'new-name.yaml' series
96
+ # use another series of configuration files with new name, use 'new-name.config.yaml' series
93
97
  another_config = AppConfig.get_config 'new-name'
94
98
 
95
99
  # you can overwrite deployment directory when get a config serie
data/Rakefile CHANGED
File without changes
@@ -57,7 +57,7 @@ class AppConfig
57
57
  end
58
58
  def self.get_config config_name = nil, config_dir = nil
59
59
  raise ConfigError, ('please call %s::setup() before getting a config instance' % self.name) if @@app_name.nil?
60
- self.new config_dir, config_name
60
+ self.new config_name, config_dir
61
61
  end
62
62
 
63
63
  def [] key
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class AppConfig
4
- VERSION = '0.0.3'
5
- end
4
+ VERSION = '0.1.0'
5
+ end
@@ -18,7 +18,10 @@ class AppConfigTest < MiniTest::Unit::TestCase
18
18
  TEST_CONFIG_NAME = 'foo.bar'
19
19
 
20
20
  # a new TestCase object created for every test method testing
21
- AppConfig.setup 'Test', File.dirname(__FILE__), ENV['TMP']
21
+ dd = File.join(ENV['TMP'] || ENV['TMPDIR'] || ENV['HOME'], 'appconf.tmp')
22
+ Dir.mkdir dd unless File.exist?(dd)
23
+ puts 'deploy dir: ' + dd
24
+ AppConfig.setup 'Test', File.dirname(__FILE__), dd
22
25
  @@config = AppConfig.get_config
23
26
 
24
27
  def self.clean
@@ -80,7 +83,11 @@ class AppConfigTest < MiniTest::Unit::TestCase
80
83
  assert_equal DIST_VALUE, query_config_value
81
84
  end
82
85
  def test_i_non_exist_value
83
- assert_equal nil, @@config['non.exist.config.item']
86
+ assert_nil @@config['non.exist.config.item']
87
+ end
88
+ def test_j_named_config
89
+ @@config = AppConfig.get_config 'test'
90
+ assert_equal DEPLOY_PLATFORM_VALUE, query_config_value
84
91
  end
85
92
 
86
93
  def test_z_clean
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Arloan Bone
@@ -11,41 +10,41 @@ bindir: bin
11
10
  cert_chain: []
12
11
  date: 2016-04-09 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: Query config values from one or more series of YAML files in priority.
13
+ description: Query config values from one or more series of YAML configuration files
14
+ in priority.
15
15
  email: arloan@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - LICENSE
21
+ - README.md
22
+ - Rakefile
20
23
  - lib/appconf.rb
21
24
  - lib/appconf_version.rb
22
25
  - test/test_appconf.rb
23
- - Rakefile
24
- - LICENSE
25
- - README.md
26
26
  homepage: https://github.com/arloan/appconf
27
27
  licenses:
28
28
  - MIT
29
+ metadata: {}
29
30
  post_install_message:
30
31
  rdoc_options: []
31
32
  require_paths:
32
33
  - lib
33
34
  required_ruby_version: !ruby/object:Gem::Requirement
34
- none: false
35
35
  requirements:
36
- - - ! '>='
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  required_rubygems_version: !ruby/object:Gem::Requirement
40
- none: false
41
40
  requirements:
42
- - - ! '>='
41
+ - - ">="
43
42
  - !ruby/object:Gem::Version
44
43
  version: '0'
45
44
  requirements: []
46
45
  rubyforge_project:
47
- rubygems_version: 1.8.24
46
+ rubygems_version: 2.6.14
48
47
  signing_key:
49
- specification_version: 3
50
- summary: App YAML Config in Priority
48
+ specification_version: 4
49
+ summary: Access YAML Config files in Priority
51
50
  test_files: []