ruby-conf 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use ruby-1.9.3-p194@rubyconf --create
1
+ rvm use ruby-1.9.3-p327@rubyconf --create
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GEM
8
8
  git (>= 1.2.5)
9
9
  rake
10
10
  rdoc
11
- json (1.7.5)
11
+ json (1.7.6)
12
12
  rake (10.0.3)
13
13
  rdoc (3.12)
14
14
  json (~> 1.4)
@@ -20,7 +20,7 @@ GEM
20
20
  rspec-core (2.12.2)
21
21
  rspec-expectations (2.12.1)
22
22
  diff-lcs (~> 1.1.3)
23
- rspec-mocks (2.12.0)
23
+ rspec-mocks (2.12.1)
24
24
  yard (0.8.3)
25
25
 
26
26
  PLATFORMS
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.0
data/lib/ruby-conf.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  #
2
2
  #
3
3
  # @author Hollin Wilkins & Curtis Schofield & Mason Bo-bay-son
4
+
5
+ $RUBY_CONF = nil
6
+
4
7
  module Magic
5
8
  attr_accessor :__rc_chain
6
9
  def __rc_gather() "#{to_s}#{__rc_chain.nil? ? "" : " #{__rc_chain.__rc_gather}"}" end
@@ -131,7 +134,7 @@ class RubyConf < BasicObject
131
134
 
132
135
  def __rc_build_string(depth = 0)
133
136
  str = ""
134
- str += "[#@__rc_name]\n" unless @__rc_parent
137
+ str += "[#{@__rc_name || "CONFIG"}]\n" unless @__rc_parent
135
138
  str += "\n"
136
139
  @__rc_attributes.keys.map{|k| k.to_s }.sort.each do |key|
137
140
  value = self[key]
@@ -145,7 +148,7 @@ class RubyConf < BasicObject
145
148
  def to_s() __rc_build_string end
146
149
  def to_str() to_s end
147
150
 
148
- def __rc_build_inspect() "#{"[#@__rc_name] " unless @__rc_parent}#{@__rc_attributes.keys.map {|k| k.to_s }.sort.map { |key| "#{key}: #{self[key].is_a?(Config) ? "{ #{self[key].__rc_build_inspect} }" : self[key].inspect}" }.join(", ")}" end
151
+ def __rc_build_inspect() "#{"[#{@__rc_name || "CONFIG"}] " unless @__rc_parent}#{@__rc_attributes.keys.map {|k| k.to_s }.sort.map { |key| "#{key}: #{self[key].is_a?(Config) ? "{ #{self[key].__rc_build_inspect} }" : self[key].inspect}" }.join(", ")}" end
149
152
  def inspect() __rc_build_inspect end
150
153
  end
151
154
 
@@ -158,6 +161,16 @@ class RubyConf < BasicObject
158
161
  const = const.to_sym
159
162
  ::Object.const_set(const, config) if !::Object.const_defined?(const) || ::Object.const_get(const).is_a?(Config)
160
163
  end
164
+
165
+ if $RUBY_CONF.nil? && (name.nil? || name.to_s =~ /^(?:Rails)?Conf/)
166
+ $RUBY_CONF = if ::Object.const_defined?(:Rails)
167
+ cfg = config[:"#{::Rails.env}"] || config[:"#{::Rails.env}_conf"] || config[:"#{::Rails.env}_config"]
168
+ cfg && cfg.detach || config
169
+ else
170
+ config
171
+ end
172
+ end
173
+
161
174
  config
162
175
  end
163
176
 
@@ -166,4 +179,12 @@ class RubyConf < BasicObject
166
179
  def self.method_missing(name, *args) @@__rc_configs[name.to_sym] end
167
180
 
168
181
  def self.respond_to?(name) @@__rc_configs.key?(name.to_sym) end
182
+
183
+ def self.clear()
184
+ $RUBY_CONF = nil
185
+ @@__rc_configs.keys.each do |config|
186
+ remove_const(config.to_sym) if config.to_s[/^[A-Z]/] && const_defined?(config.to_sym)
187
+ end
188
+ @@__rc_configs.clear
189
+ end
169
190
  end
data/ruby-conf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-conf"
8
- s.version = "2.3.0"
8
+ s.version = "2.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Curtis Schofield & Hollin Wilkins & Mason"]
12
- s.date = "2012-12-24"
12
+ s.date = "2013-01-14"
13
13
  s.description = "rubyconf is a ruby configuration dsl that aims to make it simple to write and read configurations for ruby apps without a yaml or xml file"
14
14
  s.email = "blazingpair@blazingcloud.net"
15
15
  s.extra_rdoc_files = [
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.homepage = "http://github.com/blazingpair/ruby-conf"
35
35
  s.licenses = ["MIT"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.24"
37
+ s.rubygems_version = "1.8.23"
38
38
  s.summary = "dsl (domain specific language) for config files in ruby"
39
39
 
40
40
  if s.respond_to? :specification_version then
@@ -2,6 +2,11 @@ require 'spec_helper'
2
2
  require 'ruby-conf'
3
3
 
4
4
  describe RubyConf do
5
+
6
+ before do
7
+ RubyConf.clear
8
+ end
9
+
5
10
  subject { RubyConf }
6
11
 
7
12
  describe "lambda arguments" do
@@ -28,7 +33,6 @@ describe RubyConf do
28
33
  var_args ->(*args) { "var|#{args.inspect}" }
29
34
  multi_args ->(one,two) { "multi|#{one.inspect}|#{two.inspect}" }
30
35
  multi_var_args ->(one,*two,three) { "multivar|#{one.inspect}|#{two.inspect}|#{three.inspect}" }
31
-
32
36
  end
33
37
 
34
38
  LambdaToString.to_s.should == "[LambdaToString]\n\nmulti_args: multi|nil|nil\n\nmulti_var_args: multivar|nil|[nil]|nil\n\nno_args: none\n\none_arg: one|nil\n\nvar_args: var|[nil]\n\n"
@@ -356,6 +360,55 @@ TEXT
356
360
  end.should raise_error NameError
357
361
 
358
362
  end
363
+ end
364
+ end
365
+
366
+ describe "Automatically sets the RAILS_CONF variable" do
367
+
368
+ it "sets the first unnamed config as default" do
369
+ $RUBY_CONF.should be_nil
370
+ first = RubyConf.define { ident "first" }
371
+ $RUBY_CONF.should_not be_nil
372
+ second = RubyConf.define { ident "second" }
373
+ $RUBY_CONF.should == first
374
+ $RUBY_CONF.ident.should == "first"
375
+ end
376
+
377
+ it "sets the proper config based on Rails environment and detaches, if it exists" do
378
+ module ::Rails
379
+ def self.env() "foo" end
380
+ end
381
+ ::Object.const_defined?(:Rails).should be_true
382
+
383
+ $RUBY_CONF.should be_nil
384
+ RubyConf.define do
385
+ foo { ident "correct" }
386
+ bar { ident "wrong" }
387
+ end
388
+ $RUBY_CONF.ident.should == "correct"
389
+
390
+ RubyConf.clear
391
+ $RUBY_CONF.should be_nil
392
+ RubyConf.define do
393
+ foo_conf { ident "correct" }
394
+ bar_conf { ident "wrong" }
395
+ end
396
+ $RUBY_CONF.ident.should == "correct"
397
+
398
+ RubyConf.clear
399
+ $RUBY_CONF.should be_nil
400
+ RubyConf.define do
401
+ foo_config { ident "correct" }
402
+ bar_config { ident "wrong" }
403
+ end
404
+ $RUBY_CONF.ident.should == "correct"
405
+
406
+ RubyConf.clear
407
+ $RUBY_CONF.should be_nil
408
+ RubyConf.define do
409
+ ident "correct"
410
+ end
411
+ $RUBY_CONF.ident.should == "correct"
359
412
 
360
413
  end
361
414
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-24 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: -3375656081623008669
115
+ hash: 121205113869847411
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 1.8.24
124
+ rubygems_version: 1.8.23
125
125
  signing_key:
126
126
  specification_version: 3
127
127
  summary: dsl (domain specific language) for config files in ruby