constantinople 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.8.7@constantinople
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in constantinople.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ watch(/^.+\.gemspec/)
7
+ end
8
+
9
+ guard 'rspec', :cli => '-c --format documentation -r ./spec/spec_helper.rb',
10
+ :version => 2 do
11
+ watch(%r{^spec/.+_spec\.rb})
12
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ end
@@ -0,0 +1,66 @@
1
+ Constantinople
2
+ ==============
3
+
4
+ Usage
5
+ =====
6
+ Place all your configuration parameters in YAML files within a config/
7
+ directory under the top level of your project. For example, you might have a
8
+ config/database.yml file.
9
+
10
+ In an initializer at the top level of your project,
11
+ or within your config/ directory, do this:
12
+
13
+ require 'constantinople'
14
+
15
+ You may then use CONSTANTINOPLE from anywhere in your app:
16
+
17
+ CONSTANTINOPLE.database.username
18
+
19
+
20
+ Defaults and Overrides
21
+ ======================
22
+ You can create default and over-ride versions of config files. Constantinople
23
+ will look for and load config files in the following order:
24
+
25
+ config/*.yml.default
26
+ config/*.yml
27
+ config/*.yml.override
28
+
29
+ The results are merged together. We recommended you gitignore config/*.yml.
30
+
31
+ Environments
32
+ ============
33
+ If there is a non-empty ENV['RAILS_ENV'], ENV['RACK_ENV'] or ENV['APP_ENV'] the
34
+ first such environment will be used as a key whose values will be merged into
35
+ the level above. So for example, if your database.yml file has
36
+
37
+ username: root
38
+ password:
39
+ production:
40
+ password: d87gfds09ds8a
41
+
42
+ Then in your development environment:
43
+
44
+ CONSTANTINOPLE.database.username # root
45
+ CONSTANTINOPLE.database.password # nil
46
+
47
+ And in your production environment:
48
+
49
+ CONSTANTINOPLE.database.username # root
50
+ CONSTANTINOPLE.database.password # d87gfds09ds8a
51
+
52
+
53
+ Working on the Gem
54
+ ==================
55
+ Install rvm, including ruby 1.9.2
56
+ Clone the git repo, then...
57
+
58
+ cd constantinople
59
+ gem install bundler
60
+ bundle install
61
+ rake coverage
62
+
63
+
64
+ Forking
65
+ =======
66
+ Yeah, fine. But please rename to Istanbul.
@@ -0,0 +1,24 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run all specs"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = [
7
+ '-c',
8
+ '--format documentation',
9
+ '-r ./spec/spec_helper.rb'
10
+ ]
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+
14
+ desc "open coverage report"
15
+ task :coverage do
16
+ system 'rake spec'
17
+ system 'open coverage/index.html'
18
+ end
19
+
20
+ desc "Open development console"
21
+ task :console do
22
+ puts "Loading development console..."
23
+ system "irb -I #{File.join('.', 'lib')} -r #{File.join('.', 'lib', 'constantinople')}"
24
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "constantinople/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "constantinople"
7
+ s.version = Constantinople::VERSION
8
+ s.authors = ["Chris Johnson"]
9
+ s.email = ["chris@kindkid.com"]
10
+ s.homepage = "https://github.com/kindkid/constantinople"
11
+ s.summary = "Load all your config/*.yml files"
12
+ s.description = "Supports defaults, over-rides, and environments"
13
+
14
+ s.rubyforge_project = "constantinople"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.add_dependency "map", "~> 4.2"
21
+ s.add_dependency "deep_merge", "0.2.0"
22
+ s.add_development_dependency "rspec", "~> 2.6"
23
+ s.add_development_dependency "simplecov", "~> 0.4"
24
+ s.add_development_dependency("rb-fsevent", "~> 0.4") if RUBY_PLATFORM =~ /darwin/i
25
+ s.add_development_dependency "guard", "~> 0.5"
26
+ s.add_development_dependency "guard-bundler", "~> 0.1"
27
+ s.add_development_dependency "guard-rspec", "~> 0.4"
28
+ end
@@ -0,0 +1,67 @@
1
+ require "map"
2
+ require "yaml"
3
+ require "deep_merge/core"
4
+ require "constantinople/deep_merge_map"
5
+ require "constantinople/version"
6
+
7
+ module Constantinople
8
+
9
+ def self.reload!
10
+ result = Map.new
11
+ caller_config_directories do |dir|
12
+ result.deeper_merge!(load_from_directory(dir))
13
+ end
14
+ env = environment
15
+ result.each do |key, value|
16
+ value.deeper_merge!(value[env]) if value.include?(env)
17
+ end
18
+ result # I'm the map, I'm the map, I'm the map, I'm the map...
19
+ end
20
+
21
+ private
22
+
23
+ def self.load_from_directory(dir)
24
+ result = Map.new
25
+ ['.yml.default', '.yml', '.yml.override'].each do |ext|
26
+ Dir.glob(File.join(dir,"*#{ext}")) do |path|
27
+ filename = File.basename(path,ext)
28
+ result.deeper_merge!(filename => YAML.load_file(path))
29
+ end
30
+ end
31
+ result
32
+ end
33
+
34
+ def self.environment
35
+ ['RAILS_ENV', 'RACK_ENV', 'APP_ENV'].each do |env|
36
+ environment = ENV[env]
37
+ return environment unless environment.nil? || environment.empty?
38
+ end
39
+ nil
40
+ end
41
+
42
+ def self.caller_config_directories
43
+ possible_caller_config_directories do |dir|
44
+ yield dir if File.directory?(dir)
45
+ end
46
+ end
47
+
48
+ def self.possible_caller_config_directories
49
+ caller_directories do |d|
50
+ yield File.join(d,'config')
51
+ yield File.join(File.dirname(d),'config')
52
+ end
53
+ end
54
+
55
+ def self.caller_directories
56
+ results = []
57
+ regex = /^(.*)\:\d+\:in .*$/
58
+ caller.each do |trace|
59
+ dir = File.dirname(trace)
60
+ yield dir unless results.include?(dir) || !File.directory?(dir)
61
+ results << dir
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ CONSTANTINOPLE = Constantinople.reload!
@@ -0,0 +1,13 @@
1
+ module Constantinople
2
+ module DeepMergeMap
3
+ # deep_merge! will merge and overwrite any unmergeables in destination hash
4
+ def deeper_merge!(source, options = {})
5
+ default_opts = {:preserve_unmergeables => false}
6
+ ::DeepMerge::deep_merge!(source, self, default_opts.merge(options))
7
+ end
8
+ end
9
+ end
10
+
11
+ class Map
12
+ include ::Constantinople::DeepMergeMap
13
+ end
@@ -0,0 +1,3 @@
1
+ module Constantinople
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,9 @@
1
+ b: standard
2
+ c: standard
3
+ animal: unicorn
4
+ development:
5
+ animal: dolphin
6
+ test:
7
+ animal: turtle
8
+ production:
9
+ animal: penguin
@@ -0,0 +1,3 @@
1
+ a: default
2
+ b: default
3
+ c: default
@@ -0,0 +1 @@
1
+ c: override
@@ -0,0 +1,18 @@
1
+ describe Constantinople do
2
+
3
+ before(:all) do
4
+ CONSTANTINOPLE.spec.a.should == 'default' # just showing we do auto-load
5
+
6
+ ENV['RAILS_ENV'] ||= 'test'
7
+ CONFIG = Constantinople.reload!
8
+ end
9
+
10
+ it "just works" do
11
+ CONFIG.should_not be_nil
12
+ CONFIG.spec.should_not be_nil
13
+ CONFIG.spec.a.should == 'default'
14
+ CONFIG.spec.b.should == 'standard'
15
+ CONFIG.spec.c.should == 'override'
16
+ CONFIG.spec.animal.should == 'turtle' # from test environment
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+
7
+ Bundler.require(:default, :test, :development)
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: constantinople
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Chris Johnson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-29 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: map
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 4
32
+ - 2
33
+ version: "4.2"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: deep_merge
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 0
47
+ - 2
48
+ - 0
49
+ version: 0.2.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 2
63
+ - 6
64
+ version: "2.6"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: simplecov
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ - 4
79
+ version: "0.4"
80
+ type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: rb-fsevent
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ - 4
94
+ version: "0.4"
95
+ type: :development
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ hash: 1
106
+ segments:
107
+ - 0
108
+ - 5
109
+ version: "0.5"
110
+ type: :development
111
+ version_requirements: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard-bundler
114
+ prerelease: false
115
+ requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ hash: 9
121
+ segments:
122
+ - 0
123
+ - 1
124
+ version: "0.1"
125
+ type: :development
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: guard-rspec
129
+ prerelease: false
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ - 4
139
+ version: "0.4"
140
+ type: :development
141
+ version_requirements: *id008
142
+ description: Supports defaults, over-rides, and environments
143
+ email:
144
+ - chris@kindkid.com
145
+ executables: []
146
+
147
+ extensions: []
148
+
149
+ extra_rdoc_files: []
150
+
151
+ files:
152
+ - .gitignore
153
+ - .rvmrc
154
+ - Gemfile
155
+ - Guardfile
156
+ - README.md
157
+ - Rakefile
158
+ - constantinople.gemspec
159
+ - lib/constantinople.rb
160
+ - lib/constantinople/deep_merge_map.rb
161
+ - lib/constantinople/version.rb
162
+ - spec/config/spec.yml
163
+ - spec/config/spec.yml.default
164
+ - spec/config/spec.yml.override
165
+ - spec/lib/constantinople_spec.rb
166
+ - spec/spec_helper.rb
167
+ has_rdoc: true
168
+ homepage: https://github.com/kindkid/constantinople
169
+ licenses: []
170
+
171
+ post_install_message:
172
+ rdoc_options: []
173
+
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ requirements: []
195
+
196
+ rubyforge_project: constantinople
197
+ rubygems_version: 1.6.2
198
+ signing_key:
199
+ specification_version: 3
200
+ summary: Load all your config/*.yml files
201
+ test_files:
202
+ - spec/config/spec.yml
203
+ - spec/config/spec.yml.default
204
+ - spec/config/spec.yml.override
205
+ - spec/lib/constantinople_spec.rb
206
+ - spec/spec_helper.rb