loadcfg 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +5 -0
  3. data/README.rdoc +47 -0
  4. data/Rakefile +14 -0
  5. data/lib/loadcfg.rb +21 -0
  6. data/loadcfg.gemspec +29 -0
  7. metadata +66 -0
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ v0.1
2
+ -- Allow you to load a configuration file, let's say config/whatever.yaml as constants
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ CHANGELOG
2
+ README.rdoc
3
+ Rakefile
4
+ lib/loadcfg.rb
5
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,47 @@
1
+ == loadcfg
2
+
3
+ Rails gem for read environments constants following some convention.
4
+
5
+ == Install
6
+
7
+ gem install loadcfg --source http://gems.github.com or then gem 'loadcfg' in your bundle file.
8
+
9
+ == Usage
10
+
11
+ Let's say you have some configuration constants that depends on the environment you are working on, for example config/facebook.yml
12
+
13
+ development:
14
+ app_id: <the_app_id_for_development_env>
15
+ secret_key: <the_secret_key_for_development_env>
16
+ callback_url: <the_callback_url_for_development_env>
17
+ test:
18
+ app_id: <the_app_id_for_test_env>
19
+ secret_key: <the_secret_key_for_test_env>
20
+ callback_url: <the_callback_url_for_test_env>
21
+ staging:
22
+ app_id: <the_app_id_for_staging_env>
23
+ secret_key: <the_secret_key_for_staging_env>
24
+ callback_url: <the_callback_url_for_staging_env>
25
+ production:
26
+ app_id: <the_app_id_for_production_env>
27
+ secret_key: <the_secret_key_for_production_env>
28
+ callback_url: <the_callback_url_for_production_env>
29
+
30
+ One of the conventions is that you should put the file in the config dir of your proyect, then in any class where you want to use the constants you call the loadconfig method passing the config file name as symbol, for example
31
+
32
+ class FacebookHelper
33
+ loadconfig :facebook
34
+ end
35
+
36
+ that's going to generate a constant for each key in the yaml config file with the file name as a prefix, for example
37
+
38
+ class FacebookHelper
39
+ loadconfig :facebook
40
+
41
+ def some_method_that_deals_with_facebook_api
42
+ fb_id = FACEBOOK_APP_ID
43
+ # here fb_id contains the value you gave for the environment you are working on
44
+ end
45
+ end
46
+
47
+ That's it.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('loadcfg', '0.1') do |p|
6
+ p.description = "Allow you to load any configuration constants from config/whatever.yml"
7
+ p.url = "http://github.com/j4rs/loadcfg"
8
+ p.author = "Jorge Rodriguez"
9
+ p.email = "jorge.rodriguez.suarez@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/task/*.rake"].sort.each { |ext| load ext }
data/lib/loadcfg.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'yaml'
2
+
3
+ module LoadCfg
4
+
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def loadconfig(yaml_file_name)
11
+ loaded_yaml = YAML.load_file(Rails.root.join("config/#{yaml_file_name}.yml"))[Rails.env]
12
+ loaded_yaml.keys.each do |key|
13
+ self.const_set("#{[yaml_file_name, '_', key].join.upcase}", loaded_yaml[key])
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ class Object
20
+ include LoadCfg
21
+ end
data/loadcfg.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{loadcfg}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Jorge Rodriguez}]
9
+ s.date = %q{2011-08-09}
10
+ s.description = %q{Allow you to load any configuration constants from config/whatever.yml}
11
+ s.email = %q{jorge.rodriguez.suarez@gmail.com}
12
+ s.extra_rdoc_files = [%q{CHANGELOG}, %q{README.rdoc}, %q{lib/loadcfg.rb}]
13
+ s.files = [%q{CHANGELOG}, %q{README.rdoc}, %q{Rakefile}, %q{lib/loadcfg.rb}, %q{Manifest}, %q{loadcfg.gemspec}]
14
+ s.homepage = %q{http://github.com/j4rs/loadcfg}
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Loadcfg}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
+ s.rubyforge_project = %q{loadcfg}
18
+ s.rubygems_version = %q{1.8.7}
19
+ s.summary = %q{Allow you to load any configuration constants from config/whatever.yml}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loadcfg
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Rodriguez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-09 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Allow you to load any configuration constants from config/whatever.yml
17
+ email: jorge.rodriguez.suarez@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG
24
+ - README.rdoc
25
+ - lib/loadcfg.rb
26
+ files:
27
+ - CHANGELOG
28
+ - README.rdoc
29
+ - Rakefile
30
+ - lib/loadcfg.rb
31
+ - Manifest
32
+ - loadcfg.gemspec
33
+ homepage: http://github.com/j4rs/loadcfg
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --line-numbers
39
+ - --inline-source
40
+ - --title
41
+ - Loadcfg
42
+ - --main
43
+ - README.rdoc
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "1.2"
58
+ requirements: []
59
+
60
+ rubyforge_project: loadcfg
61
+ rubygems_version: 1.8.7
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Allow you to load any configuration constants from config/whatever.yml
65
+ test_files: []
66
+