configuration_manager 0.1.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/configuration_manager.gemspec +23 -0
- data/lib/configuration_manager/configuration.rb +13 -0
- data/lib/configuration_manager/railtie.rb +7 -0
- data/lib/configuration_manager/version.rb +3 -0
- data/lib/configuration_manager.rb +53 -0
- data/lib/tasks/config.rake +27 -0
- metadata +95 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bruz Marzolf
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Configuration Manager
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Rails development configuration management and theme switching. This is specific
|
5
|
+
to how application configuration and theme handling are done at CX, and hasn't
|
6
|
+
been made more generally useful yet.
|
7
|
+
|
8
|
+
Install
|
9
|
+
-------
|
10
|
+
|
11
|
+
Add to your Gemfile:
|
12
|
+
|
13
|
+
gem "configuration_manager"
|
14
|
+
|
15
|
+
In your ApplicationController:
|
16
|
+
|
17
|
+
include ConfigurationManager
|
18
|
+
|
19
|
+
if Rails.env.development? || Rails.env.test?
|
20
|
+
before_filter :reload_config
|
21
|
+
before_filter :check_configuration_freshness
|
22
|
+
end
|
23
|
+
|
24
|
+
If there are configurations that should be ignored, add them in config/initializers/configuration_manager.rb:
|
25
|
+
|
26
|
+
ConfigurationManager.configure do |config|
|
27
|
+
config.ignored_configs = [:key_to_ignore, :another_one]
|
28
|
+
end
|
29
|
+
|
30
|
+
Add default theme configurations as config/application.{theme name}.dev.yml. All of these will require updates whenever new developement configurations are added.
|
31
|
+
|
32
|
+
Usage
|
33
|
+
-----
|
34
|
+
|
35
|
+
Update to the latest config for the current theme:
|
36
|
+
|
37
|
+
rake config:update
|
38
|
+
|
39
|
+
Switch themes:
|
40
|
+
|
41
|
+
rake config:switch THEME={theme name}
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'configuration_manager/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "configuration_manager"
|
8
|
+
spec.version = ConfigurationManager::VERSION
|
9
|
+
spec.authors = ["Bruz Marzolf"]
|
10
|
+
spec.email = ["bruz@cx.com"]
|
11
|
+
spec.description = %q{Manage development configurations for themed apps}
|
12
|
+
spec.summary = %q{Themed app configuration management}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ConfigurationManager
|
2
|
+
class Configuration < Struct.new(:ignored_configs)
|
3
|
+
end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
|
8
|
+
def configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
yield(configuration) if block_given?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "configuration_manager/configuration"
|
2
|
+
require "configuration_manager/railtie"
|
3
|
+
require "configuration_manager/version"
|
4
|
+
|
5
|
+
module ConfigurationManager
|
6
|
+
|
7
|
+
def reload_config
|
8
|
+
AppConfig.reload!
|
9
|
+
rescue Errno::ENOENT
|
10
|
+
raise "Missing the application.yml configuration file. Try loading with " +
|
11
|
+
"`cp config/application.cx.dev.yml config/application.yml`"
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_configuration_freshness
|
15
|
+
current = "application.yml"
|
16
|
+
reference = "application.#{AppConfig.theme}.dev.yml"
|
17
|
+
|
18
|
+
current_path = "#{Rails.root}/config/#{current}"
|
19
|
+
reference_path = "#{Rails.root}/config/#{reference}"
|
20
|
+
|
21
|
+
different = configs_different? current_path, reference_path
|
22
|
+
|
23
|
+
if different && !AppConfig['allow_custom_configuration']
|
24
|
+
raise "Current configuration #{current} does not match #{reference}. " +
|
25
|
+
"Either run `rake config:update` or set allow_custom_configuration to true" +
|
26
|
+
" in your application.yml."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def configs_different?(path_one, path_two)
|
33
|
+
one = YAML.load_file(path_one)
|
34
|
+
two = YAML.load_file(path_two)
|
35
|
+
|
36
|
+
relevant_configs_one = relevant_configs(one)
|
37
|
+
relevant_configs_two = relevant_configs(two)
|
38
|
+
|
39
|
+
relevant_configs_one != relevant_configs_two
|
40
|
+
end
|
41
|
+
|
42
|
+
def relevant_configs(data)
|
43
|
+
ignored_configs = ConfigurationManager.configuration.ignored_configs
|
44
|
+
|
45
|
+
ignored_configs.each do |config|
|
46
|
+
["development", "test"].each do |env|
|
47
|
+
data[env].delete config.to_s if data[env]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
data
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
namespace :config do
|
2
|
+
desc "Switch configurations to another theme, specieid by THEME"
|
3
|
+
task :switch do
|
4
|
+
theme = ENV['THEME']
|
5
|
+
|
6
|
+
puts "= Switching to the #{theme} configuration"
|
7
|
+
copy_theme(theme)
|
8
|
+
|
9
|
+
puts "= Clearing temp files"
|
10
|
+
Rake::Task["tmp:clear"].invoke
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Update the current configuration"
|
14
|
+
task :update do
|
15
|
+
theme = AppConfig.theme
|
16
|
+
|
17
|
+
puts "= Updating config, using the #{theme} configuration"
|
18
|
+
copy_theme(theme)
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_theme(theme)
|
22
|
+
source = "#{Rails.root}/config/application.#{theme}.dev.yml"
|
23
|
+
dest = "#{Rails.root}/config/application.yml"
|
24
|
+
|
25
|
+
system "cp #{source} #{dest}"
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configuration_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bruz Marzolf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Manage development configurations for themed apps
|
47
|
+
email:
|
48
|
+
- bruz@cx.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- configuration_manager.gemspec
|
59
|
+
- lib/configuration_manager.rb
|
60
|
+
- lib/configuration_manager/configuration.rb
|
61
|
+
- lib/configuration_manager/railtie.rb
|
62
|
+
- lib/configuration_manager/version.rb
|
63
|
+
- lib/tasks/config.rake
|
64
|
+
homepage: ''
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
hash: 912823216979744525
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
hash: 912823216979744525
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.25
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Themed app configuration management
|
95
|
+
test_files: []
|