266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/fluent/config.rb', line 266
def config_param(name, *args, &block)
name = name.to_sym
opts = {}
args.each {|a|
if a.is_a?(Symbol)
opts[:type] = a
elsif a.is_a?(Hash)
opts.merge!(a)
else
raise ArgumentError, "wrong number of arguments (#{1+args.length} for #{block ? 2 : 3})"
end
}
type = opts[:type]
if block && type
raise ArgumentError, "wrong number of arguments (#{1+args.length} for #{block ? 2 : 3})"
end
block ||= case type
when :string, nil
Proc.new {|val| val }
when :integer
Proc.new {|val| val.to_i }
when :float
Proc.new {|val| val.to_f }
when :size
Proc.new {|val| Config.size_value(val) }
when :bool
Proc.new {|val| Config.bool_value(val) }
when :time
Proc.new {|val| Config.time_value(val) }
else
raise ArgumentError, "unknown config_param type `#{type}'"
end
params = config_params_set
params.delete(name)
params[name] = [block, opts]
if opts.has_key?(:default)
config_set_default(name, opts[:default])
end
attr_accessor name
end
|