host_config 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +39 -27
- data/lib/host_config.rb +3 -2
- metadata +15 -15
- data/MIT-LICENSE +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5064acc25e2c89418d968e3db81b80113fd1f1b
|
4
|
+
data.tar.gz: f5646bd4e02b77549f53d71428e86b95f2dc4909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dfa5b6ad69c12073a68aa709e4e82c61e0c06bbe68205bfbe410027285c0e7e7b798a61ae8317b9fd08bf65b686a214244ea3e352e28cbe79895a13163ff5a0
|
7
|
+
data.tar.gz: 2c3c3c3745ca12572ecf5e810378cd36bdca18268025facf6641f46b5cba07bc1a1d0d43cbc5fbc5369aadb214e88c809b7eebfb084e36119f5fb35fca9a6e71
|
data/README.md
CHANGED
@@ -7,20 +7,26 @@ Simple per-host configuration for Rails 4.
|
|
7
7
|
|
8
8
|
First add it to your `Gemfile`:
|
9
9
|
|
10
|
-
|
10
|
+
``` ruby
|
11
|
+
gem 'host_config'
|
12
|
+
```
|
11
13
|
|
12
14
|
Then make an initializer (or add it to one you already have, like so):
|
13
15
|
|
14
|
-
|
16
|
+
``` ruby
|
17
|
+
AppConfig = HostConfig.init!
|
18
|
+
```
|
15
19
|
|
16
20
|
That's really it. This will attempt to load `config/hosts/HOSTNAME.yml`
|
17
21
|
and assign an OpenStruct to `AppConfig` which you can then use all over
|
18
22
|
your app. You can also override the hostname:
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
``` ruby
|
25
|
+
override_hostname = Rails.env.production? ? 'aws' :
|
26
|
+
Rails.env.staging? ? 'staging' :
|
27
|
+
nil
|
28
|
+
AppConfig = HostConfig.init! hostname: override_hostname
|
29
|
+
```
|
24
30
|
|
25
31
|
...or something similar, so that you can share config for production environments.
|
26
32
|
This is a good alternative to environment variables. You can handle your configuration
|
@@ -29,12 +35,14 @@ to the git repo, but adding it to each host out of band).
|
|
29
35
|
|
30
36
|
You can also add more values to it for things that aren't host-specific:
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
``` ruby
|
39
|
+
AppConfig.analytics_id = 'UA-XXXXXXXX-Y'
|
40
|
+
AppConfig.sanitize = Sanitize::Config::RELAXED
|
41
|
+
AppConfig.sanitize[:attributes]['a'] = %w{ target href name }
|
42
|
+
AppConfig.sanitize[:add_attributes] = {
|
43
|
+
'a' => { 'target' => '_blank' }
|
44
|
+
}
|
45
|
+
```
|
38
46
|
|
39
47
|
...can be quite convenient.
|
40
48
|
|
@@ -43,27 +51,31 @@ You can also add more values to it for things that aren't host-specific:
|
|
43
51
|
|
44
52
|
Configuration is in YAML files.
|
45
53
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
``` yml
|
55
|
+
---
|
56
|
+
force_ssl: true
|
57
|
+
protocol: https
|
58
|
+
application_host: myapp.com
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
60
|
+
twitter:
|
61
|
+
consumer: ABC
|
62
|
+
secret: XYZ
|
54
63
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
64
|
+
vegetables:
|
65
|
+
- broccoli
|
66
|
+
- carrots
|
67
|
+
- corn
|
68
|
+
```
|
59
69
|
|
60
70
|
As simple as that. You can also setup common stuff in files prefixed with `_`. Eg,
|
61
71
|
`_defaults.yml`, and load either before or after the stuff in the primary config:
|
62
72
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
``` yml
|
74
|
+
---
|
75
|
+
load_before:
|
76
|
+
- defaults
|
77
|
+
other_stuff: 'here'
|
78
|
+
```
|
67
79
|
|
68
80
|
This will look for `_defaults.yml` and deep-merge in the rest. You can also use
|
69
81
|
`load_after`, which will of course override values in the primary config... why would
|
data/lib/host_config.rb
CHANGED
@@ -2,12 +2,13 @@ require 'ostruct'
|
|
2
2
|
require 'socket'
|
3
3
|
|
4
4
|
module HostConfig
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.2"
|
6
6
|
|
7
7
|
class MissingConfigFile < StandardError; end
|
8
8
|
|
9
9
|
class << self
|
10
10
|
def init!( opts={} )
|
11
|
+
@base_path = opts[:base_path] || Rails.root
|
11
12
|
@logger = opts[:logger] || Rails.logger
|
12
13
|
@hostname = opts[:hostname] || Socket.gethostname.split('.').shift
|
13
14
|
@config = {}
|
@@ -20,7 +21,7 @@ module HostConfig
|
|
20
21
|
|
21
22
|
def load_config( file )
|
22
23
|
begin
|
23
|
-
path =
|
24
|
+
path = File.join( @base_path, 'config', 'hosts', "#{file}.yml" )
|
24
25
|
data = File.read(path)
|
25
26
|
YAML.load( data )
|
26
27
|
rescue Errno::ENOENT
|
metadata
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: host_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Funduk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.0
|
20
|
-
type: :
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.0
|
27
|
-
description:
|
26
|
+
version: '4.0'
|
27
|
+
description: HostConfig is easy app configuration for Ruby apps.
|
28
28
|
email:
|
29
29
|
- ryan.funduk@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- lib/host_config.rb
|
35
|
-
- MIT-LICENSE
|
36
|
-
- Rakefile
|
37
34
|
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/host_config.rb
|
38
37
|
homepage: https://github.com/rfunduk/host_config
|
39
|
-
licenses:
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
40
|
metadata: {}
|
41
41
|
post_install_message:
|
42
42
|
rdoc_options: []
|
@@ -44,17 +44,17 @@ require_paths:
|
|
44
44
|
- lib
|
45
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.2.2
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Simple per-host configuration for Rails 4.
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright 2013 Ryan Funduk
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|