ruby-conf 2.5.3 → 2.6.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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.6.0
data/lib/ruby-conf.rb CHANGED
@@ -7,6 +7,10 @@ require 'digest/md5'
7
7
 
8
8
  module RubyConf
9
9
 
10
+ def self.puts(logger = $stdout, *obj) logger.puts(*obj) if logger.respond_to?(:puts) end
11
+ def self.err(*objs) self.puts($stderr, *objs) end
12
+ def self.out(*objs) self.puts($stdout, *objs) end
13
+
10
14
  class Loader < BasicObject
11
15
  EXTENTIONS = %w{rbc rbcnf rbconf rbconfig rubyconf rubyconfig ruby-conf ruby-config}
12
16
 
@@ -21,12 +25,12 @@ module RubyConf
21
25
  __rc_set_conf
22
26
  if load(path) && @@conf
23
27
  @@path, @@mtime, @@md5 = path, File.mtime(path).to_i, Digest::MD5.hexdigest(File.read(path))
24
- puts "[ruby-conf] Auto-Loaded config at path: #{path}"
28
+ RubyConf.out "[ruby-conf] Auto-Loaded config at path: #{path}"
25
29
  end
26
30
  end
27
31
  def method_missing(name, *args, &block)
28
32
  if @@mtime && @@mtime != File.mtime(@@path).to_i && @@md5 != Digest::MD5.hexdigest(File.read(@@path))
29
- puts "[ruby-conf] Detected change in config file, reloading..."
33
+ RubyConf.err "[ruby-conf] Detected change in config file, reloading..."
30
34
  __rc_load(@@path)
31
35
  end
32
36
 
@@ -41,6 +45,7 @@ module RubyConf
41
45
  @@conf.__send__(name, *args, &block)
42
46
  end
43
47
  def to_s() @@conf.to_s end
48
+ def to_str() @@conf.to_str end
44
49
  def inspect() @@conf.inspect end
45
50
  end
46
51
  end
@@ -175,18 +180,38 @@ module RubyConf
175
180
  str += "[#{@__rc_name || "CONFIG"}]\n" unless @__rc_parent
176
181
  str += "\n"
177
182
  @__rc_attributes.keys.map{|k| k.to_s }.sort.each do |key|
178
- value = self[key]
183
+ value = begin
184
+ self[key]
185
+ rescue => e
186
+ "[UNRESOLVED]"
187
+ end
188
+
179
189
  str += " " * depth
180
190
  str += "#{key}:"
181
191
  str += value.is_a?(Config) ? value.__rc_build_string(depth+1) : " #{value}\n"
182
- str += "\n" unless depth > 0
192
+ # str += "\n" unless depth > 0
183
193
  end
184
194
  str
185
195
  end
196
+ def __rc_build_inspect()
197
+ istr = ""
198
+ istr += "[#{@__rc_name || "CONFIG"}] " unless @__rc_parent
199
+ istr += @__rc_attributes.keys.map{|k| k.to_s }.sort.map{ |key|
200
+ str = ""
201
+ value = begin
202
+ self[key]
203
+ rescue => e
204
+ "[UNRESOLVED:#{e}]"
205
+ end
206
+ str += "#{key}: "
207
+ str += value.is_a?(Config) ? "{ #{value.__rc_build_inspect} }" : value.inspect
208
+ str
209
+ }.join(", ")
210
+ istr
211
+ end
212
+
186
213
  def to_s() __rc_build_string end
187
214
  def to_str() to_s end
188
-
189
- 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
190
215
  def inspect() __rc_build_inspect end
191
216
  end
192
217
 
@@ -197,6 +222,10 @@ module RubyConf
197
222
  @@__rc_configs.clear
198
223
  end
199
224
 
225
+ def to_s() @@__rc_configs.to_s end
226
+ def to_str() @@__rc_configs.to_str end
227
+ def inspect() @@__rc_configs.inspect end
228
+
200
229
  def [](name) @@__rc_configs[name.to_sym] end
201
230
  def method_missing(name, *args) @@__rc_configs[name.to_sym] end
202
231
  def respond_to?(name) @@__rc_configs.key?(name.to_sym) 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.5.3"
8
+ s.version = "2.6.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-14"
12
+ s.date = "2013-01-15"
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,15 @@ describe RubyConf do
34
34
  multi_var_args ->(one,*two,three) { "multivar|#{one.inspect}|#{two.inspect}|#{three.inspect}" }
35
35
  end
36
36
 
37
- 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"
37
+ LambdaToString.to_s.should == <<-TOS
38
+ [LambdaToString]
39
+
40
+ multi_args: multi|nil|nil
41
+ multi_var_args: multivar|nil|[nil]|nil
42
+ no_args: none
43
+ one_arg: one|nil
44
+ var_args: var|[nil]
45
+ TOS
38
46
  end
39
47
  end
40
48
 
@@ -98,6 +106,29 @@ describe RubyConf do
98
106
  end
99
107
 
100
108
  describe ".to_s" do
109
+
110
+ it "does it's best to print procs but will fail gracefully" do
111
+ RubyConf.define :ProcStrings do
112
+ valid ->{ "valid return" }
113
+ valid_args ->(a, b, c){ "all empty > a:#{a} b:#{b} c:#{c}" }
114
+ broken ->{ raise "oops" }
115
+ broken_args ->(a, b, c){ raise "oops: a:#{a} b:#{b} c:#{c}" }
116
+ end
117
+
118
+ tos = <<-STR
119
+ [ProcStrings]
120
+
121
+ broken: [UNRESOLVED]
122
+ broken_args: [UNRESOLVED]
123
+ valid: valid return
124
+ valid_args: all empty > a: b: c:
125
+ STR
126
+
127
+ ProcStrings.to_s.should == tos
128
+ ProcStrings.to_str.should == tos
129
+ ProcStrings.inspect.should == '[ProcStrings] broken: "[UNRESOLVED:oops]", broken_args: "[UNRESOLVED:oops: a: b: c:]", valid: "valid return", valid_args: "all empty > a: b: c:"'
130
+ end
131
+
101
132
  it "prints out the config in a human readable way" do
102
133
  RubyConf.define("some shapes", :as => :Shapes) {
103
134
  defaults { position { px 10; py 20 }; size { width 100; height 200 }; rotation lambda { '90 degrees' } }
@@ -127,14 +158,12 @@ circle:
127
158
  size:
128
159
  height: 200
129
160
  width: 100
130
-
131
161
  dafuq:
132
162
  holy: fuck this is some god damn evil fucking black sorcery
133
163
  how: the hell did he make this happen
134
164
  mason: is some kind of sorcerer
135
165
  srsly: dude
136
166
  this: is freaking me out man
137
-
138
167
  defaults:
139
168
  position:
140
169
  px: 10
@@ -143,11 +172,9 @@ defaults:
143
172
  size:
144
173
  height: 200
145
174
  width: 100
146
-
147
175
  other:
148
176
  color: blue like the color of the sea before a storm
149
177
  sides: 4
150
-
151
178
  polygon:
152
179
  details:
153
180
  actual_sides: 100
@@ -155,7 +182,6 @@ polygon:
155
182
  seems: like a lot of damn sides
156
183
  named: somename
157
184
  sides: many
158
-
159
185
  square:
160
186
  named: rectangle
161
187
  position:
@@ -165,7 +191,6 @@ square:
165
191
  size:
166
192
  height: 200
167
193
  width: 50
168
-
169
194
  triangle:
170
195
  named: rectangle
171
196
  position:
@@ -175,7 +200,6 @@ triangle:
175
200
  size:
176
201
  height: 200
177
202
  width: 5
178
-
179
203
  TEXT
180
204
  end
181
205
 
@@ -383,6 +407,10 @@ TEXT
383
407
  end
384
408
 
385
409
  it "will autoload the first ruby-conf that it can find if none is provided" do
410
+ module RubyConf
411
+ def self.puts(*args) end
412
+ end
413
+
386
414
  dir = Dir["./**/test_conf.rb.tmpl"].first[/^(.*?)\/test_conf.rb.tmpl$/, 1]
387
415
 
388
416
  val = Random.rand.to_s
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.5.3
4
+ version: 2.6.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-14 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: 540271139098183150
118
+ hash: 2745882013736486446
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements: