rails_simple_config 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.
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rails_simple_config.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_simple_config (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ rails_simple_config!
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2011 by Chris Stefano - virtualstaticvoid@gmail.com
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.
@@ -0,0 +1,103 @@
1
+ # Rails Simple Config
2
+
3
+ A simple YAML based configuration for Ruby on Rails 3+, which supports shared settings, ERB and more.
4
+
5
+ Inspired in part by the database configuration in Rails, [app_config](https://github.com/die-antwort/app_config) and [rails_config](https://github.com/railsjedi/rails_config).
6
+
7
+ ## Installation
8
+
9
+ Add RailsSimpleConfig to your Gemfile:
10
+
11
+ gem 'rails_simple_config'
12
+
13
+ Run the generator to create the default configuration file:
14
+
15
+ rails generate rails_simple_config:install
16
+
17
+ ## Usage
18
+
19
+ ### Define configuration settings
20
+
21
+ Define your settings in the generated `config.yml` file, found in your Rails root directory.
22
+
23
+ The file contains sections for the development, test and production Rails environments, and a shared section.
24
+ It can also contain ERB code so that more advanced configuration scenarios can be supported.
25
+
26
+ # example configuration
27
+
28
+ shared: &shared
29
+ title: My Website Title
30
+ description: Meta description of the site
31
+ keywords: Meta keywords for search engines
32
+
33
+ no_reply_email: noreply@example.com
34
+
35
+ development:
36
+ # inherit shared settings
37
+ <<: *shared
38
+
39
+ # define additional settings and overrides
40
+
41
+ # e.g. mail settings for mailcatcher
42
+ smtp_server: localhost
43
+ smtp_port: 1025
44
+ mail_prefix: DEV -
45
+
46
+ production:
47
+ # inherit shared settings
48
+ <<: *shared
49
+
50
+ # define additional settings and overrides
51
+
52
+ # e.g. mail settings for send grid
53
+ smtp_server: www.sendgrid.com
54
+ smtp_port: 25
55
+
56
+ ### Access configuration settings
57
+
58
+ To access configuration settings in your Rails application, use the `SimpleConfig` global module.
59
+
60
+ For example, in your application layout:
61
+
62
+ <html>
63
+ <head>
64
+ <title><%= SimpleConfig.title %></title>
65
+ <meta name="description" content="<%= SimpleConfig.description %>" />
66
+ <meta name="keywords" content="<%= SimpleConfig.keywords %>" />
67
+
68
+ ...
69
+
70
+ </head>
71
+ <body>
72
+
73
+ ...
74
+
75
+ </body>
76
+ </html>
77
+
78
+ In addition, unlike other Rails configuration solutions, `SimpleConfig` is available to the development, test and production configurations, initializers and routes during startup.
79
+ It can be used as a replacement for environment variables; thus making your setup much cleaner.
80
+
81
+ For example, the `SimpleConfig.no_reply_email` will be accessible to the [devise](https://github.com/plataformatec/devise) initializer when configuring `mailer_sender`:
82
+
83
+ # extract of the devise.rb initializer
84
+ Devise.setup do |config|
85
+
86
+ # ==> Mailer Configuration
87
+ # Configure the e-mail address which will be shown in DeviseMailer.
88
+ config.mailer_sender = SimpleConfig.no_reply_email
89
+
90
+ ...
91
+
92
+ end
93
+
94
+ ### Notes
95
+
96
+ `SimpleConfig` inherits from [ActiveSupport::OrderedOptions](http://api.rubyonrails.org/classes/ActiveSupport/OrderedOptions.html), so accessing undefined settings will always return `nil`.
97
+
98
+ ## Project Info
99
+
100
+ RailsSimpleConfig is hosted on [Github](http://github.com/virtualstaticvoid/rails_simple_config), where your contributions, forkings, comments and feedback are greatly welcomed.
101
+
102
+ Copyright © 2011 Chris Stefano, released under the MIT license.
103
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,6 @@
1
+ Description:
2
+ Creates the default configuration file (config.yml) in the project root directory.
3
+
4
+ Example:
5
+ `rails generate rails_simple_config:install`
6
+
@@ -0,0 +1,10 @@
1
+ module RailsSimpleConfig
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_files
6
+ template "config.yml", "./config.yml"
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,65 @@
1
+ ##
2
+ # Configuration settings for use by the Rails application
3
+ # Made available via the SimpleConfig global class
4
+ # Use for settings such as mail server configurations, Amazon keys and secrets etc...
5
+ # You can use ERB too
6
+ #
7
+
8
+ ##
9
+ # Define shared settings
10
+ #
11
+ shared: &shared
12
+
13
+ # application settings
14
+ title: Example
15
+ description:
16
+ keywords:
17
+ version:
18
+
19
+ # url settings
20
+ scheme: http
21
+ domain: example.com
22
+
23
+ # mail settings
24
+ smtp_domain: www.example.com
25
+ smtp_server:
26
+ smtp_user_name:
27
+ smtp_password:
28
+
29
+ # email addresses
30
+ info_email: info@example.com
31
+ no_reply_email: noreply@example.com
32
+ support_email: support@example.com
33
+
34
+ ##
35
+ # Define settings per Rails environment,
36
+ # provide overrides to the shared settings as needed
37
+ #
38
+ development:
39
+ # inherit shared settings
40
+ <<: *shared
41
+
42
+ # url settings
43
+ subdomain: dev
44
+ domain: localhost:3000
45
+
46
+ # mail setting (for mailcatcher)
47
+ smtp_server: localhost
48
+ smtp_port: 1025
49
+
50
+ test:
51
+ # inherit shared settings
52
+ <<: *shared
53
+
54
+ # url settings
55
+ subdomain: test
56
+
57
+ production:
58
+ # inherit shared settings
59
+ <<: *shared
60
+
61
+ # url settings
62
+ subdomain: www
63
+
64
+
65
+
@@ -0,0 +1,40 @@
1
+ require "rails_simple_config/version"
2
+ require "rails_simple_config/railtie"
3
+
4
+ module RailsSimpleConfig
5
+ end
6
+
7
+ module SimpleConfig
8
+
9
+ class Config < ActiveSupport::OrderedOptions
10
+
11
+ def load!
12
+ puts "Loading configuration for '#{Rails.env}'."
13
+ filename = Rails.root + 'config.yml'
14
+ if File.exist?(filename)
15
+ configuration = YAML.load(ERB.new(File.read(filename)).result)[Rails.env]
16
+ configuration.each do |key, value|
17
+ self.__send__("#{key}=", value)
18
+ end if configuration
19
+ end
20
+ end
21
+
22
+ def reload!
23
+ clear
24
+ load!
25
+ end
26
+
27
+ end
28
+
29
+ @@config = Config.new
30
+
31
+ def self.load!
32
+ @@config.load!
33
+ end
34
+
35
+ def self.method_missing(method, *args)
36
+ @@config.__send__(method, *args)
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,22 @@
1
+ require 'rails_simple_config'
2
+
3
+ module RailsSimpleConfig
4
+ class Railtie < Rails::Railtie
5
+
6
+ # load the configuration before the respective environment configuration file is loaded!
7
+ initializer :load_simple_config, :before => :load_environment_config do
8
+ ::SimpleConfig.reload!
9
+ end
10
+
11
+ # Rails Dev should reload the configuration on each request
12
+ if Rails.env.development?
13
+ initializer :load_simple_config_development do
14
+ ActionController::Base.class_eval do
15
+ prepend_before_filter { ::SimpleConfig.reload! }
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,3 @@
1
+ module RailsSimpleConfig
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rails_simple_config/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rails_simple_config"
7
+ s.summary = %q{Simple YAML based configuration gem for Rails 3+}
8
+ s.description = %q{A simple YAML based configuration for Ruby on Rails 3+, which supports shared settings, ERB and more.}
9
+
10
+ s.authors = ["Chris Stefano"]
11
+ s.email = ["virtualstaticvoid@gmail.com"]
12
+
13
+ s.homepage = "https://github.com/virtualstaticvoid/rails_simple_config"
14
+
15
+ s.version = RailsSimpleConfig::VERSION
16
+ s.platform = Gem::Platform::RUBY
17
+
18
+ s.rubyforge_project = "rails_simple_config"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_simple_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Stefano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-23 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: A simple YAML based configuration for Ruby on Rails 3+, which supports
15
+ shared settings, ERB and more.
16
+ email:
17
+ - virtualstaticvoid@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - MIT-LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - lib/generators/rails_simple_config/install/USAGE
29
+ - lib/generators/rails_simple_config/install/install_generator.rb
30
+ - lib/generators/rails_simple_config/install/templates/config.yml
31
+ - lib/rails_simple_config.rb
32
+ - lib/rails_simple_config/railtie.rb
33
+ - lib/rails_simple_config/version.rb
34
+ - rails_simple_config.gemspec
35
+ homepage: https://github.com/virtualstaticvoid/rails_simple_config
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: rails_simple_config
55
+ rubygems_version: 1.8.6
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Simple YAML based configuration gem for Rails 3+
59
+ test_files: []