autoconfig 0.0.1

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.
Files changed (3) hide show
  1. data/README.markdown +40 -0
  2. data/autoconfig.rb +40 -0
  3. metadata +68 -0
data/README.markdown ADDED
@@ -0,0 +1,40 @@
1
+ !!!plain
2
+
3
+ | | / __/
4
+ __ _ _ _| |_ ___ ___ ___ _ __ | |_ _ __ _
5
+ / _` | | | | __|/ _ \ / __|/ _ \| '_ \| _| |/ _` |
6
+ | (_| | |_| | |_| (_) | (__| (_) | | | | | | | (_| |
7
+ \__,_|\__,_|\__|\___/ \___|\___/|_| |_|_| |_|\__, |
8
+ __/ |
9
+ |___/
10
+
11
+ ## What is it
12
+
13
+ Autoconfig in an automated way to create flexible configuration structures representing your YAML configuration
14
+
15
+ ## How does it work
16
+
17
+ 1. require 'autoconfig'
18
+ 2. profit!
19
+
20
+ ## Example
21
+
22
+ Lets say you have application.yml in your config folder:
23
+
24
+ defaults:
25
+ web:
26
+ hostname: 'localhost'
27
+ noreply: noreply@myhost.com
28
+ support_email: support@myhost.com
29
+ production:
30
+ web:
31
+ hostname: "the.production.com"
32
+
33
+ After requiring 'autoconfig' you should expect ApplicationConfig structure that will contain all the information. In production environment
34
+ ApplicationConfig.web.hostname call will return "the.production.com".
35
+
36
+ ## Configuration
37
+
38
+ By default, it will look at config directory of your project and transfer most of your .yml files (it ignores database ones). However,
39
+ you have full control over where it need to look and what to convert.
40
+
data/autoconfig.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+ module AutoConfig
5
+ def self.root
6
+ ENV['AUTOCONFIG_ROOT'] || ENV['APP_ROOT'] || Rails.root
7
+ end
8
+
9
+ def self.pattern
10
+ ENV['AUTOCONFIG_PATTERN'] || 'config/*.yml'
11
+ end
12
+
13
+ def self.path
14
+ ENV['AUTOCONFIG_PATH'] || File.expand_path(pattern, root)
15
+ end
16
+
17
+ def self.environment
18
+ ENV['AUTOCONFIG_ENV'] || ENV['APP_ENV'] || Rails.env
19
+ end
20
+
21
+ files = Dir.glob(path)
22
+
23
+ begin
24
+ old_verbose, $VERBOSE = $VERBOSE, nil
25
+
26
+ files.each do |file|
27
+ name = File.basename(file, '.yml')
28
+ next if name.match(/database/)
29
+
30
+ config = YAML.load_file(file)
31
+ app_config = config['common'] || {}
32
+ app_config.update(config['defaults'] || {})
33
+ app_config.update(config[environment] || {})
34
+
35
+ Object::const_set("#{name}Config".camelize.intern, OpenStruct.new(app_config))
36
+ end
37
+ ensure
38
+ $VERBOSE = old_verbose
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autoconfig
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - tjbladez
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-10 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Automated way to create flexible configuration structures representing your YAML configuration
23
+ email: tjbladez@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - autoconfig.rb
32
+ - README.markdown
33
+ has_rdoc: true
34
+ homepage: http://github.com/tjbladez/autoconfig
35
+ licenses: []
36
+
37
+ post_install_message: Forget about loading your yaml configuration
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Automagically creates Config structures from your config/*.yml files
67
+ test_files: []
68
+