ruby-conf 2.7.2 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 2.8.0
data/lib/ruby-conf.rb CHANGED
@@ -73,7 +73,7 @@ module RubyConf
73
73
  end
74
74
 
75
75
  class Config
76
- attr_reader :__rc_attributes, :__rc_parent, :__rc_name, :__rc_chains, :__rc_locked
76
+ attr_reader :__rc_attributes, :__rc_parent, :__rc_name, :__rc_chains, :__rc_locked, :__rc_static_values
77
77
 
78
78
  def __rc_root() __rc_parent ? __rc_parent.__rc_root : self end
79
79
  def detach(parent = nil)
@@ -85,7 +85,7 @@ module RubyConf
85
85
  end
86
86
 
87
87
  def initialize(name = nil, parent = nil, &block)
88
- @__rc_locked, @__rc_attributes, @__rc_chains, @__rc_parent = false, {}, [], parent
88
+ @__rc_locked, @__rc_attributes, @__rc_chains, @__rc_parent, @__rc_static_values = false, {}, [], parent, {}
89
89
  @__rc_name = name.to_sym if name
90
90
  instance_eval(&block) if block_given?
91
91
  __rc_lock
@@ -97,6 +97,12 @@ module RubyConf
97
97
  self
98
98
  end
99
99
 
100
+ def __rc_static_proc(name, *args)
101
+ name = name.to_sym
102
+ static_key = "#{name}:#{args}"
103
+ @__rc_static_values[static_key] || self[name, *args]
104
+ end
105
+
100
106
  def [](name, *args)
101
107
  name = name.to_sym
102
108
  value = @__rc_attributes[name]
@@ -109,7 +115,10 @@ module RubyConf
109
115
  else
110
116
  @@stack << name
111
117
  begin
112
- __rc_root.instance_exec(*args, &value)
118
+ value = __rc_root.instance_exec(*args, &value)
119
+ static_key = "#{name}:#{args}"
120
+ @__rc_static_values[static_key] = value
121
+ value
113
122
  ensure
114
123
  @@stack.delete(name)
115
124
  end
@@ -198,11 +207,24 @@ module RubyConf
198
207
  end
199
208
 
200
209
  if args.empty?
201
- modifier == '?' ? !!self[name] : self[name]
210
+ if modifier == '?'
211
+ !!self[name]
212
+ elsif modifier == '!' && __rc_attributes[name.to_sym].is_a?(Proc)
213
+ __rc_static_proc(name)
214
+ else
215
+ self[name]
216
+ end
202
217
  else
203
218
  arg = args.size == 1 ? args.first : args
204
-
205
- (@__rc_locked && __rc_attributes[name.to_sym].is_a?(Proc)) ? self[name, *args] : self[name] = arg
219
+ if @__rc_locked && __rc_attributes[name.to_sym].is_a?(Proc)
220
+ if modifier == '!'
221
+ __rc_static_proc(name, *args)
222
+ else
223
+ self[name, *args]
224
+ end
225
+ else
226
+ self[name] = arg
227
+ end
206
228
  end
207
229
  end
208
230
  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.7.2"
8
+ s.version = "2.8.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 = "2013-01-23"
12
+ s.date = "2013-02-28"
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 = [
@@ -13,6 +13,46 @@ describe RubyConf do
13
13
  subject { RubyConf }
14
14
 
15
15
  describe "lambda arguments" do
16
+
17
+ it "uses bang to ensure lambdas get called only once" do
18
+ RubyConf.define :Lambang do
19
+ noargs -> { "#{rand(1000)}" }
20
+ bang ->(a, b) { "#{a}-#{b}-#{rand(1000)}" }
21
+ end
22
+
23
+ normal = Lambang.noargs
24
+ Lambang.noargs!.should == normal
25
+ Lambang.noargs.should_not == normal
26
+
27
+ bang = Lambang.noargs!
28
+ Lambang.noargs!.should == bang
29
+
30
+ #reset it by not using bang
31
+ Lambang.noargs.should_not == bang
32
+
33
+ bang2 = Lambang.noargs!
34
+ bang2.should_not == bang
35
+ Lambang.noargs!.should == bang2
36
+
37
+
38
+ normal = Lambang.bang(:a, :b)
39
+ Lambang.bang!(:a, :b).should == normal
40
+ Lambang.bang(:a, :b).should_not == normal
41
+
42
+ bangcd = Lambang.bang!(:c, :d)
43
+ bangef = Lambang.bang!(:e, :f)
44
+ Lambang.bang!(:c, :d).should == bangcd
45
+ Lambang.bang!(:e, :f).should == bangef
46
+ Lambang.bang!(:c, :d).should == bangcd
47
+
48
+ #reset it by not using bang
49
+ Lambang.bang(:c, :d).should_not == bangcd
50
+
51
+ bangcd2 = Lambang.bang!(:c, :d)
52
+ bangcd2.should_not == bangcd
53
+ Lambang.bang!(:c, :d).should == bangcd2
54
+ end
55
+
16
56
  it "handles hash arguments properly" do
17
57
  RubyConf.define :LambdaHashes do
18
58
  key ->(options) {
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.7.2
4
+ version: 2.8.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: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 3704553343926456777
134
+ hash: 1480920585190021958
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  none: false
137
137
  requirements: