cleverua_application_config 2.0
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.
- data/Gemfile +10 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +29 -0
- data/lib/application_config.rb +16 -0
- data/lib/application_config.yml +11 -0
- data/lib/engine.rb +9 -0
- data/lib/generators/application_config/install_generator.rb +13 -0
- data/lib/kernel_extension.rb +17 -0
- metadata +75 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
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.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
== application_config functionality
|
2
|
+
|
3
|
+
'application_config' eases project configuring by introducing erb enabled yaml config file in RAILS_ROOT/config folder and provides handful methods accessing config values based on current rails environment. So, you can have separate sets of configuration properties for each rails environment you use.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem 'application_config', '2.0'
|
8
|
+
|
9
|
+
== Default configuration file
|
10
|
+
|
11
|
+
During installation plugin will create default config in RAILS_ROOT/config/application_config.yml, it looks like the following (please note it's okay to put ERB tags in there)
|
12
|
+
|
13
|
+
development: &defaults
|
14
|
+
items_per_page: 25
|
15
|
+
secure_with_basic_auth: false
|
16
|
+
base_url: development.com
|
17
|
+
erb_enabled_property: <%= "#{Rails.root}/something" %>
|
18
|
+
test:
|
19
|
+
<<: *defaults
|
20
|
+
base_url: test.com
|
21
|
+
production:
|
22
|
+
<<: *defaults
|
23
|
+
base_url: production.com
|
24
|
+
|
25
|
+
== Usage
|
26
|
+
|
27
|
+
You then can access those values using 'property' method:
|
28
|
+
class FooController < ApplicationController
|
29
|
+
def index
|
30
|
+
@base_url = property(:base_url)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
This will set @base_url with value 'development.com' if you run that in development environment.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
Rake::TestTask.new(:test) do |t|
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.libs << 'test'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = false
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => :test
|
22
|
+
|
23
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'ApplicationConfig'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README.rdoc')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require "active_support/dependencies"
|
3
|
+
require 'yaml'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module ApplicationConfig
|
7
|
+
|
8
|
+
mattr_accessor :app_root, :app_config_data
|
9
|
+
|
10
|
+
def self.setup
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
|
14
|
+
require "engine"
|
15
|
+
require "kernel_extension"
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
development: &defaults
|
2
|
+
items_per_page: 25
|
3
|
+
secure_with_basic_auth: false
|
4
|
+
base_url: development.com
|
5
|
+
erb_enabled_property: <%= "#{Rails.root}/something" %>
|
6
|
+
test:
|
7
|
+
<<: *defaults
|
8
|
+
base_url: test.com
|
9
|
+
production:
|
10
|
+
<<: *defaults
|
11
|
+
base_url: production.com
|
data/lib/engine.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module ApplicationConfig
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
def self.source_root
|
6
|
+
@source_root ||= File.join(File.dirname(__FILE__))
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy_application_config_file
|
10
|
+
copy_file "../../application_config.yml", "config/application_config.yml"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Kernel
|
2
|
+
def property(key)
|
3
|
+
app_config_file_path = ApplicationConfig.app_root.join('config', 'application_config.yml')
|
4
|
+
if File.exists?(app_config_file_path)
|
5
|
+
ApplicationConfig.app_config_data = YAML::load(ERB.new(IO.read(app_config_file_path)).result)
|
6
|
+
begin
|
7
|
+
ApplicationConfig.app_config_data[Rails.env][key.to_s]
|
8
|
+
rescue => e
|
9
|
+
raise("Failed to get '#{key}' configuration property")
|
10
|
+
end
|
11
|
+
else
|
12
|
+
raise "Application configuration file does not found under #{ApplicationConfig.app_root.join('config')} folder! Please make sure you ran application_config:install generator."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :prop, :property
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cleverua_application_config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: "2.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Boris Babusenko
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-02-10 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: "'application_config' eases project configuring by introducing erb enabled yaml config file in RAILS_ROOT/config folder and provides handful methods accessing config values based on current rails environment. So, you can have separate sets of configuration properties for each rails environment you use."
|
22
|
+
email:
|
23
|
+
- boris@cleverua.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/generators/application_config/install_generator.rb
|
32
|
+
- lib/engine.rb
|
33
|
+
- lib/application_config.yml
|
34
|
+
- lib/application_config.rb
|
35
|
+
- lib/kernel_extension.rb
|
36
|
+
- MIT-LICENSE
|
37
|
+
- Rakefile
|
38
|
+
- Gemfile
|
39
|
+
- README.rdoc
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: https://github.com/cleverua/application_config
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.6.2
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Adds application_config.yml file to 'config' folder in your Rails app.
|
74
|
+
test_files: []
|
75
|
+
|