simple_app_config 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT license
2
+
3
+ Copyright (c) 2009 Patrick Huesler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,65 @@
1
+ = simple app config
2
+
3
+ Generates a configuration object:
4
+
5
+ * Pass in a YAML file
6
+ * Pass in an environment as a filter
7
+ * Use YAML defaults
8
+ * Use ERB
9
+ * Returns an OpenStruct so top level attributes can be accessed via method
10
+
11
+ Here is how a configuration file could look like:
12
+
13
+ application: RailsConfig
14
+ version: <%= 'version'.upcase %>
15
+
16
+ defaults: &defaults
17
+ payment:
18
+ key: payment_key
19
+
20
+ development:
21
+ <<: *defaults
22
+ payment:
23
+ key: development_payment_key
24
+
25
+ production:
26
+ <<: *defaults
27
+
28
+ == Installation
29
+
30
+ === Via github
31
+ gem install phuesler-simple_app_config
32
+
33
+ === Via gem cutter (http://www.gemcutter.org)
34
+ gem install gemcutter
35
+ gem tumble
36
+ gem install simple_app_config
37
+
38
+ == Usage
39
+
40
+ require 'simple_app_config'
41
+ Config = AppConfig.create("config/application.yml", :environment => 'development')
42
+
43
+ puts Config.application
44
+ puts Config.payment['key']
45
+
46
+ When used in a Rails project, create an initializer and add something like this:
47
+
48
+ require 'simple_app_config'
49
+ Config = AppConfig.create("#{Rails.root}/config/application.yml", :environment => Rails.env)
50
+
51
+
52
+ == Note on Patches/Pull Requests
53
+
54
+ * Fork the project.
55
+ * Make your feature addition or bug fix.
56
+ * Add tests for it. This is important so I don't break it in a
57
+ future version unintentionally.
58
+ * Commit, do not mess with rakefile, version, or history.
59
+ (if you want to have your own version, that is fine but
60
+ bump version in a commit by itself I can ignore when I pull)
61
+ * Send me a pull request. Bonus points for topic branches.
62
+
63
+ == Copyright
64
+
65
+ Copyright (c) 2009 Patrick Huesler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "simple_app_config"
8
+ gem.summary = %Q{A little helper to define and access the app configuration}
9
+ gem.description = %Q{Use yml and erb and speficiy environments and scopes}
10
+ gem.email = "patrick.huesler@gmail.com"
11
+ gem.homepage = "http://github.com/phuesler/simple_app_config"
12
+ gem.authors = ["Patrick Huesler"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "simple_app_config #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/lib/app_config.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'ostruct'
2
+ require 'erb'
3
+ class AppConfig
4
+ def self.create(yaml_file, options = {})
5
+ yaml_data = YAML::load(ERB.new(IO.read(yaml_file)).result)
6
+ data = {}
7
+ data = yaml_data.delete(options[:environment]) if options[:environment]
8
+ data.merge!(yaml_data)
9
+ OpenStruct.new(data)
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simple_app_config}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Patrick Huesler"]
12
+ s.date = %q{2009-10-04}
13
+ s.description = %q{Use yml and erb and speficiy environments and scopes}
14
+ s.email = %q{patrick.huesler@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/app_config.rb",
27
+ "simple_app_config.gemspec",
28
+ "test/app_config_test.rb",
29
+ "test/fixtures/application.yml",
30
+ "test/test_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/phuesler/simple_app_config}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{A little helper to define and access the app configuration}
37
+ s.test_files = [
38
+ "test/app_config_test.rb",
39
+ "test/test_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+ class AppConfigTest < Test::Unit::TestCase
3
+ TEST_FILE = File.join(File.dirname(__FILE__),"fixtures","application.yml")
4
+
5
+ def test_method_accessor_for_top_level_attributes
6
+ config = AppConfig.create(TEST_FILE)
7
+ assert_equal "RailsConfig", config.application
8
+ end
9
+
10
+ def test_read_a_scoped_attribute
11
+ config = AppConfig.create(TEST_FILE, :environment => 'development')
12
+ assert_equal "development_payment_key", config.payment['key']
13
+ end
14
+
15
+ def test_attributes_are_inherited
16
+ config = AppConfig.create(TEST_FILE, :environment => 'production')
17
+ assert_equal "payment_key", config.payment['key']
18
+ end
19
+
20
+ def test_erb_rendering
21
+ config = AppConfig.create(TEST_FILE)
22
+ assert_equal 'VERSION', config.version
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ application: RailsConfig
2
+ version: <%= 'version'.upcase %>
3
+
4
+ defaults: &defaults
5
+ payment:
6
+ key: payment_key
7
+
8
+ development:
9
+ <<: *defaults
10
+ payment:
11
+ key: development_payment_key
12
+
13
+ production:
14
+ <<: *defaults
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'app_config'
7
+
8
+ class Test::Unit::TestCase
9
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_app_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Huesler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-04 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Use yml and erb and speficiy environments and scopes
17
+ email: patrick.huesler@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/app_config.rb
33
+ - simple_app_config.gemspec
34
+ - test/app_config_test.rb
35
+ - test/fixtures/application.yml
36
+ - test/test_helper.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/phuesler/simple_app_config
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A little helper to define and access the app configuration
65
+ test_files:
66
+ - test/app_config_test.rb
67
+ - test/test_helper.rb