config_fu 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ == 0.0.2 2009-03-23
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+ * Added Tests
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ config_fu.gemspec
6
+ lib/config_fu.rb
7
+ test/test_config_fu.rb
8
+ test/test_helper.rb
@@ -0,0 +1,63 @@
1
+ = config_fu
2
+
3
+ http://github.com/railsbros/config_fu
4
+
5
+ A very simple gem that allows environment specific configuration within a Rails application.
6
+
7
+ Get it from Github: http://github.com/railsbros/config_fu
8
+
9
+ == EXAMPLE
10
+
11
+ Create a Rails initializer named 'config_fu.rb' with your custom config code:
12
+
13
+ ConfigFu::Configuration.configure do |config|
14
+ config.service_provider = "CentralProvider"
15
+ config.thumbs = 4
16
+ config.exception_handler = "MyExceptionHandler"
17
+ end
18
+
19
+ # special config for developent environment
20
+ ConfigFu::Configuration.configure(:development) do |config|
21
+ end
22
+
23
+ # special config for test environment
24
+ ConfigFu::Configuration.configure(:test) do |config|
25
+ config.service_provider = "MockProvider"
26
+ config.exception_handler = "MockExceptionHandler"
27
+ end
28
+
29
+ # special config for production environment
30
+ ConfigFu::Configuration.configure(:production) do |config|
31
+ config.service_provider = "MasterProvider"
32
+ config.thumbs = 10
33
+ config.exception_handler = "MailExceptionHandler"
34
+ end
35
+
36
+ And add the following to your Rails environment:
37
+
38
+ config.gem "railsbros-config_fu", :lib => "config_fu", :source => "http://gems.github.com"
39
+
40
+ == LICENSE:
41
+
42
+ (The MIT License)
43
+
44
+ Copyright (c) 2009 Dirk Breuer
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ 'Software'), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ %w[rubygems rake rake/clean fileutils newgem hoe].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/config_fu'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.spec('config_fu') do
7
+ developer('Dirk Breuer', 'dirk@railsbros.de')
8
+ post_install_message = "Place your config_fu.rb into the config dir."
9
+ rubyforge_name = "config_fu"
10
+ extra_dev_deps = [
11
+ ['newgem', ">= #{::Newgem::VERSION}"],
12
+ ['mocha']
13
+ ]
14
+
15
+ clean_globs |= %w[**/.DS_Store tmp *.log]
16
+ end
17
+
18
+ require 'newgem/tasks' # load /tasks/*.rake
19
+ Dir['tasks/**/*.rake'].each { |t| load t }
20
+
21
+ task :default => :test
22
+
23
+ desc "Run unit tests"
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'test'
26
+ t.test_files = FileList['test/*_test.rb']
27
+ t.verbose = true
28
+ t.warning = false
29
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{config_fu}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dirk Breuer"]
9
+ s.date = %q{2010-02-13}
10
+ s.description = %q{}
11
+ s.email = ["dirk@railsbros.de"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "config_fu.gemspec", "lib/config_fu.rb", "test/test_config_fu.rb", "test/test_helper.rb"]
14
+ s.homepage = %q{http://github.com/railsbros/config_fu}
15
+ s.rdoc_options = ["--main", "README.txt"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{config_fu}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{}
20
+ s.test_files = ["test/test_config_fu.rb", "test/test_helper.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.3"])
28
+ s.add_development_dependency(%q<gemcutter>, [">= 0.3.0"])
29
+ s.add_development_dependency(%q<hoe>, [">= 2.5.0"])
30
+ else
31
+ s.add_dependency(%q<rubyforge>, [">= 2.0.3"])
32
+ s.add_dependency(%q<gemcutter>, [">= 0.3.0"])
33
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<rubyforge>, [">= 2.0.3"])
37
+ s.add_dependency(%q<gemcutter>, [">= 0.3.0"])
38
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'singleton'
5
+
6
+ module ConfigFu
7
+ class <<self
8
+ attr_accessor :config
9
+
10
+ def method_missing(meth, *args, &blk)
11
+ if config.respond_to?(meth)
12
+ config.send(meth)
13
+ else
14
+ raise NoMethodError, "No such config element '#{meth}' could be found."
15
+ end
16
+ end
17
+ end
18
+
19
+ class Configuration
20
+ include Singleton
21
+
22
+ def self.configure(env = Rails.env.to_sym)
23
+ env = [env].flatten
24
+ return unless env.include?(Rails.env.to_sym)
25
+
26
+ yield instance if block_given?
27
+ ConfigFu.config = instance
28
+ end
29
+
30
+ def method_missing(meth, *args)
31
+ if meth.to_s =~ /\w+=/
32
+ self.class.send(:attr_accessor, meth.to_s.gsub(/=/, ''))
33
+ send(meth, *args)
34
+ end
35
+ end
36
+ end
37
+
38
+ VERSION = '0.1.3'
39
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestConfigFu < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Rails.stubs(:env => 'development')
7
+ end
8
+
9
+ def test_should_add_config_methods_dynamically
10
+ ConfigFu::Configuration.configure { |config| config.mailer = "MockMailer" }
11
+ assert_equal "MockMailer", ConfigFu.config.mailer
12
+ end
13
+
14
+ def test_should_respect_environment_specific_config_before_the_general_one
15
+ ConfigFu::Configuration.configure { |config| config.mailer = "MockMailer" }
16
+ assert_equal "MockMailer", ConfigFu.config.mailer
17
+
18
+ ConfigFu::Configuration.configure(:development) { |config| config.mailer = "DevelopmentMailer" }
19
+ assert_equal "DevelopmentMailer", ConfigFu.config.mailer
20
+ end
21
+
22
+ def test_should_allow_configs_for_multiple_environments
23
+ ConfigFu::Configuration.configure { |config| config.mailer = "MockMailer" }
24
+ assert_equal "MockMailer", ConfigFu.config.mailer
25
+
26
+ ConfigFu::Configuration.configure([:development, :staging]) { |config| config.mailer = "DevelopmentMailer" }
27
+ assert_equal "DevelopmentMailer", ConfigFu.config.mailer
28
+ end
29
+
30
+ def test_should_ignore_config_if_the_current_environment_doesnt_matches_the_given_one
31
+ ConfigFu::Configuration.configure { |config| config.mailer = "MockMailer" }
32
+ assert_equal "MockMailer", ConfigFu.config.mailer
33
+
34
+ ConfigFu::Configuration.configure(:production) { |config| config.mailer = "LiveMailer" }
35
+ assert_equal "MockMailer", ConfigFu.config.mailer
36
+ end
37
+
38
+ def test_should_access_config_elements_on_top_level
39
+ ConfigFu::Configuration.configure { |config| config.mailer = "MockMailer" }
40
+ assert_equal "MockMailer", ConfigFu.mailer
41
+ end
42
+
43
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+
3
+ require 'test/unit'
4
+ require 'mocha'
5
+
6
+ require File.dirname(__FILE__) + '/../lib/config_fu'
7
+
8
+ class Rails; end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: config_fu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 3
9
+ version: 0.1.3
10
+ platform: ruby
11
+ authors:
12
+ - Dirk Breuer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-16 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rubyforge
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 3
31
+ version: 2.0.3
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: gemcutter
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 3
44
+ - 0
45
+ version: 0.3.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: hoe
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 5
58
+ - 0
59
+ version: 2.5.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: ""
63
+ email:
64
+ - dirk@railsbros.de
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - History.txt
71
+ - Manifest.txt
72
+ - README.txt
73
+ files:
74
+ - History.txt
75
+ - Manifest.txt
76
+ - README.txt
77
+ - Rakefile
78
+ - config_fu.gemspec
79
+ - lib/config_fu.rb
80
+ - test/test_config_fu.rb
81
+ - test/test_helper.rb
82
+ has_rdoc: true
83
+ homepage: http://github.com/railsbros/config_fu
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --main
89
+ - README.txt
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: config_fu
109
+ rubygems_version: 1.3.6
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: ""
113
+ test_files:
114
+ - test/test_config_fu.rb
115
+ - test/test_helper.rb