configutron 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 neal clark
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.
data/README.markdown ADDED
@@ -0,0 +1,64 @@
1
+ configutron
2
+ ===========
3
+
4
+ configutron is a rails gemplugin for simple, application wide configuration variables specific to a rails environment. there are a grip of projects like this; each does it differently, and this is how i like to do it. all the ones I tried seemed too heavy handed. i am publishing this as a convenience for me to use in projects i work on.
5
+
6
+ usage
7
+ -----
8
+
9
+ use the gem in your rails project:
10
+
11
+ Rails::Initializer.run do |config|
12
+ config.gem 'configutron'
13
+ end
14
+
15
+ create a folder *config/settings* and a file named after each of your rails environments:
16
+
17
+ % mkdir config/settings
18
+ % touch config/settings/development.yml config/settings/test.yml config/settings/production.yml
19
+
20
+ add your variables to those files:
21
+
22
+ % echo "--- \nvariable: value\n" > config/settings/development.yml
23
+
24
+ make sure it works:
25
+
26
+ % ./script/console
27
+ Loading development environment (Rails 2.3.5)
28
+ >> Configutron.variable
29
+ => "value"
30
+
31
+ name it something easier to type:
32
+
33
+ Rails::Initializer.run do |config|
34
+ config.gem 'configutron'
35
+ end
36
+
37
+ Configutron.constant = 'App'
38
+
39
+ then back in the console:
40
+
41
+ % ./script/console
42
+ Loading development environment (Rails 2.3.5)
43
+ >> App.variable
44
+ => "value"
45
+
46
+ inspiration
47
+ -----------
48
+ * [Christopher J. Bottaro](http://github.com/cjbottaro/app_config/)'s app_config
49
+ * [Brian Smith](http://swig505.com)
50
+
51
+ note on patches/pull requests
52
+ -----------------------------
53
+ * fork the project.
54
+ * make your feature addition or bug fix.
55
+ * add tests for it. this is important so i don't break it in a
56
+ future version unintentionally.
57
+ * commit, do not mess with rakefile, version, or history.
58
+ (if you want to have your own version, that is fine but bump version in a commit by itself i can ignore when i pull)
59
+ * send me a pull request. bonus points for topic branches.
60
+
61
+
62
+ copyright
63
+ ---------
64
+ copyright (c) 2010 neal clark. See LICENSE for details (MIT License).
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "configutron"
8
+ gem.summary = %Q{simple app-wide settings for rails apps}
9
+ gem.description = %Q{simple app-wide settings for rails applications}
10
+ gem.email = "nclark@thrownproject.com"
11
+ gem.homepage = "http://github.com/nclark/configutron"
12
+ gem.authors = ["Neal Clark"]
13
+ gem.add_dependency "activesupport", ">= 0"
14
+ gem.add_runtime_dependency "activesupport", ">= 0"
15
+ gem.add_development_dependency "rspec", ">= 1.2.9"
16
+ gem.files = [
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/configutron.rb",
23
+ "lib/to_openstruct.rb",
24
+ "rails/init.rb",
25
+ "spec/configutron_spec.rb",
26
+ "spec/spec.opts",
27
+ "spec/spec_helper.rb",
28
+ "spec/fake_rails_root/config/settings/development.yml"
29
+ ]
30
+ end
31
+ Jeweler::GemcutterTasks.new
32
+ rescue LoadError
33
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
34
+ end
35
+
36
+ require 'spec/rake/spectask'
37
+ Spec::Rake::SpecTask.new(:spec) do |spec|
38
+ spec.libs << 'lib' << 'spec'
39
+ spec.spec_files = FileList['spec/**/*_spec.rb']
40
+ end
41
+
42
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
43
+ spec.libs << 'lib' << 'spec'
44
+ spec.pattern = 'spec/**/*_spec.rb'
45
+ spec.rcov = true
46
+ end
47
+
48
+ task :spec => :check_dependencies
49
+
50
+ task :default => :spec
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION.yml') ? File.read('VERSION.yml') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "configutron #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'core_ext'
4
+
5
+ module Configutron
6
+ extend self
7
+
8
+ def constant=(name)
9
+ Kernel.const_set(name, Configutron)
10
+ end
11
+
12
+ private
13
+ def method_missing(key)
14
+ configutron[key].to_openstruct || nil
15
+ end
16
+
17
+ def settings_path
18
+ File.expand_path("#{RAILS_ROOT}/config/settings/#{RAILS_ENV}.yml")
19
+ end
20
+
21
+ def configutron
22
+ @configutron ||= YAML.load_file(settings_path).symbolize_keys
23
+ end
24
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "configutron"
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ RAILS_ROOT = File.join(File.dirname(__FILE__), 'fake_rails_root')
3
+ RAILS_ENV = 'development'
4
+
5
+ describe Configutron do
6
+ before do
7
+ @fixture_path = File.expand_path(File.dirname(__FILE__) + "/fake_rails_root/config/settings/development.yml")
8
+ end
9
+
10
+ describe "module methods" do
11
+ describe ".constant=" do
12
+ it "should alias the Configutron constant to something you actually want to use" do
13
+ Configutron.constant = 'App'
14
+ Configutron.should == App
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "settings file" do
20
+ before do
21
+ Configutron.should_receive(:settings_path).and_return(@fixture_path)
22
+ end
23
+
24
+ specify "is loaded from config/settings based on the RAILS_ENV" do
25
+ lambda { Configutron.some_variable }.should_not raise_error
26
+ end
27
+ end
28
+
29
+ describe "non-nested settings" do
30
+ specify "strings can be accessed" do
31
+ Configutron.my_string.should == 'string'
32
+ end
33
+
34
+ specify "integers can be accessed" do
35
+ Configutron.my_integer.should == 1
36
+ end
37
+
38
+ specify "arrays can be accessed" do
39
+ Configutron.my_array.should == [1,2,3,4]
40
+ end
41
+
42
+ specify "hashes can be accesed" do
43
+ Configutron.my_hash.one.should == 1
44
+ Configutron.my_hash.two.should == 2
45
+ end
46
+ end
47
+
48
+ describe "nested settings" do
49
+ specify "can be accessed" do
50
+ Configutron.two.three.should == 3
51
+ end
52
+
53
+ describe "nested settings" do
54
+ specify "can be accessed" do
55
+ Configutron.four.five.six.should == 6
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ some_variable: some value
2
+
3
+ my_string: string
4
+
5
+ my_integer: 1
6
+
7
+ my_array:
8
+ - 1
9
+ - 2
10
+ - 3
11
+ - 4
12
+
13
+ my_hash:
14
+ one: 1
15
+ two: 2
16
+
17
+ two:
18
+ three: 3
19
+
20
+ four:
21
+ five:
22
+ six: 6
23
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'configutron'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ require 'rubygems'
8
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configutron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Neal Clark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-30 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.9
44
+ version:
45
+ description: simple app-wide settings for rails applications
46
+ email: nclark@thrownproject.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.markdown
54
+ files:
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.markdown
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/configutron.rb
61
+ - rails/init.rb
62
+ - spec/configutron_spec.rb
63
+ - spec/fake_rails_root/config/settings/development.yml
64
+ - spec/spec.opts
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/nclark/configutron
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: simple app-wide settings for rails apps
94
+ test_files:
95
+ - spec/configutron_spec.rb
96
+ - spec/spec_helper.rb