utilrb 2.0.2.b2 → 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.boring +40 -0
  3. data/.gitignore +13 -0
  4. data/.travis.yml +5 -0
  5. data/CMakeLists.txt +18 -0
  6. data/Gemfile +3 -0
  7. data/Makefile +8 -0
  8. data/Manifest.txt +0 -8
  9. data/{README.rd → README.md} +11 -7
  10. data/Rakefile +16 -63
  11. data/benchmarks/validate_options.rb +79 -0
  12. data/ext/utilrb/extconf.rb +1 -17
  13. data/ext/utilrb/utilrb.cc +0 -23
  14. data/lib/utilrb/column_formatter.rb +8 -5
  15. data/lib/utilrb/common.rb +1 -6
  16. data/lib/utilrb/enumerable/uniq.rb +2 -8
  17. data/lib/utilrb/event_loop.rb +5 -10
  18. data/lib/utilrb/kernel/load_dsl_file.rb +1 -2
  19. data/lib/utilrb/kernel/options.rb +25 -29
  20. data/lib/utilrb/logger/hierarchy.rb +0 -1
  21. data/lib/utilrb/logger/io.rb +3 -3
  22. data/lib/utilrb/logger/root.rb +12 -6
  23. data/lib/utilrb/module/ancestor_p.rb +0 -12
  24. data/lib/utilrb/module/is_singleton.rb +6 -0
  25. data/lib/utilrb/module/singleton_class_p.rb +14 -0
  26. data/lib/utilrb/object/attribute.rb +33 -65
  27. data/lib/utilrb/object/singleton_class.rb +1 -20
  28. data/lib/utilrb/pkgconfig.rb +21 -10
  29. data/lib/utilrb/socket/tcp_server.rb +2 -2
  30. data/lib/utilrb/spawn.rb +1 -1
  31. data/lib/utilrb/test.rb +65 -0
  32. data/lib/utilrb/thread_pool.rb +11 -13
  33. data/lib/utilrb/timepoints.rb +15 -0
  34. data/lib/utilrb/value_set.rb +10 -1
  35. data/lib/utilrb/version.rb +4 -0
  36. data/lib/utilrb/weakref.rb +11 -12
  37. data/lib/utilrb/yard.rb +0 -111
  38. data/lib/utilrb.rb +6 -1
  39. data/lib/yard-utilrb.rb +1 -0
  40. data/manifest.xml +19 -0
  41. data/package.xml +29 -0
  42. data/utilrb.gemspec +27 -0
  43. metadata +56 -107
  44. data/ext/utilrb/proc.c +0 -39
  45. data/ext/utilrb/readline.c +0 -52
  46. data/ext/utilrb/weakref.cc +0 -143
  47. data/lib/utilrb/models/inherited_enumerable.rb +0 -341
  48. data/lib/utilrb/models/registration.rb +0 -115
  49. data/lib/utilrb/module/inherited_enumerable.rb +0 -6
  50. data/lib/utilrb/objectstats.rb +0 -193
  51. data/lib/utilrb/ruby_object_graph.rb +0 -384
  52. data/test/data/test_pkgconfig.pc +0 -9
  53. data/test/data/test_pkgconfig_empty.pc +0 -10
  54. data/test/test_array.rb +0 -15
  55. data/test/test_config.rb +0 -4
  56. data/test/test_dir.rb +0 -22
  57. data/test/test_enumerable.rb +0 -119
  58. data/test/test_event_loop.rb +0 -407
  59. data/test/test_exception.rb +0 -38
  60. data/test/test_gc.rb +0 -34
  61. data/test/test_hash.rb +0 -102
  62. data/test/test_kernel.rb +0 -300
  63. data/test/test_logger.rb +0 -204
  64. data/test/test_misc.rb +0 -42
  65. data/test/test_models.rb +0 -212
  66. data/test/test_module.rb +0 -126
  67. data/test/test_object.rb +0 -77
  68. data/test/test_objectstats.rb +0 -26
  69. data/test/test_pkgconfig.rb +0 -84
  70. data/test/test_proc.rb +0 -31
  71. data/test/test_set.rb +0 -19
  72. data/test/test_thread_pool.rb +0 -409
  73. data/test/test_time.rb +0 -47
  74. data/test/test_unbound_method.rb +0 -23
  75. data/test/test_weakref.rb +0 -81
@@ -8,13 +8,13 @@ class Logger
8
8
  @logger, @level = logger, level
9
9
  @buffer = ''
10
10
  end
11
- def puts(msg)
11
+ def puts(*msg)
12
12
  print msg
13
13
  logger.send(level, @buffer)
14
14
  @buffer = ''
15
15
  end
16
- def print(msg)
17
- @buffer << msg
16
+ def print(*msg)
17
+ @buffer << msg.join("")
18
18
  end
19
19
  end
20
20
 
@@ -41,9 +41,15 @@ class Logger
41
41
  #
42
42
  def self.Root(progname, base_level, &block)
43
43
  begin
44
- base_level = ENV['BASE_LOG_LEVEL'].upcase.to_sym if ENV['BASE_LOG_LEVEL']
45
- base_level = ::Logger.const_get( base_level ) if base_level.is_a? Symbol
46
- rescue Exception => e
44
+ if ENV['BASE_LOG_LEVEL']
45
+ env_level = ENV['BASE_LOG_LEVEL'].upcase.to_sym
46
+ # there is currently no disabled level on the ruby side
47
+ # but fatal is the closest
48
+ env_level = :FATAL if env_level == :DISABLE
49
+
50
+ base_level = ::Logger.const_get( env_level )
51
+ end
52
+ rescue Exception
47
53
  raise ArgumentError, "Log level #{base_level} is not available in the ruby Logger"
48
54
  end
49
55
 
@@ -51,10 +57,10 @@ class Logger
51
57
  formatter =
52
58
  if block then lambda(&block)
53
59
  elsif HAS_COLOR
54
- lambda do |severity, time, progname, msg|
55
- console.color("#{progname}[#{severity}]: #{msg}\n", *LEVEL_TO_COLOR[severity])
60
+ lambda do |severity, time, name, msg|
61
+ console.color("#{name}[#{severity}]: #{msg}\n", *LEVEL_TO_COLOR[severity])
56
62
  end
57
- else lambda { |severity, time, progname, msg| "#{progname}[#{severity}]: #{msg}\n" }
63
+ else lambda { |severity, time, name, msg| "#{name}[#{severity}]: #{msg}\n" }
58
64
  end
59
65
 
60
66
  Module.new do
@@ -1,19 +1,7 @@
1
- require 'utilrb/common'
2
1
  class Module
3
2
  def has_ancestor?(klass) # :nodoc:
4
3
  self <= klass
5
4
  end
6
5
  end
7
- class Class
8
- def has_ancestor?(klass) # :nodoc:
9
- # We first test
10
- # self <= class
11
- # as self.superclass goes to the next *CLASS* in the chain, i.e. skips
12
- # included modules
13
- #
14
- # Then, the superclass test is used in case +self+ is a singleton
15
- self <= klass || (superclass <= klass)
16
- end
17
- end
18
6
 
19
7
 
@@ -0,0 +1,6 @@
1
+ require 'utilrb/module/singleton_class_p'
2
+ puts "WARN Module#is_singleton? has been renamed to #singleton_class? to match the built-in method in Ruby 2.1+"
3
+ puts "WARN require 'utilrb/module/singleton_class_p instead of is_singleton?"
4
+ class Module
5
+ alias :is_singleton? :singleton_class?
6
+ end
@@ -0,0 +1,14 @@
1
+ class Module
2
+ if !method_defined?(:singleton_class?)
3
+ # It so happens that this method to determine whether a class is a
4
+ # singleton class is valid for ruby 2.0 and breaks on 2.1 ... However
5
+ # (!) on 2.1 singleton_class? is defined
6
+ def singleton_class?
7
+ if instance_variable_defined?(:@__utilrb_singleton_class)
8
+ @__utilrb_singleton_class
9
+ else
10
+ @__utilrb_singleton_class = (ancestors.first == self)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,68 +1,36 @@
1
- require 'utilrb/common'
2
- require 'utilrb/object/singleton_class'
3
-
4
- Utilrb.unless_ext do
5
- class Object
6
- # call-seq:
7
- # attribute :name => default_value
8
- # attribute(:name) { default_value }
9
- #
10
- # In the first form, defines a read-write attribute
11
- # named 'name' with default_value for default value.
12
- # In the second form, the block is called if the attribute
13
- # is read before it has been ever written, and its return
14
- # value is used as default value.
15
- def attribute(attr_def, &init)
16
- if Hash === attr_def
17
- name, defval = attr_def.to_a.flatten
18
- else
19
- name = attr_def
20
- end
21
-
22
- class_eval do
23
- attr_writer name
24
- define_method("#{name}_defval") do
25
- defval || (instance_eval(&init) if init)
26
- end
27
- end
28
-
29
- class_eval <<-EOD, __FILE__, __LINE__+1
30
- def #{name}
31
- if defined? @#{name} then @#{name}
32
- else @#{name} = #{name}_defval
33
- end
34
- end
35
- EOD
36
- end
37
- end
38
- end
39
-
40
- Utilrb.if_ext do
41
- class Object
42
- def attribute(attr_def, &init) # :nodoc:
43
- if Hash === attr_def
44
- name, defval = attr_def.to_a.flatten
45
- else
46
- name = attr_def
47
- end
48
-
49
- class_eval do
50
- attr_writer name
51
- if !defval && init
52
- define_method("#{name}_defval", &init)
53
- else
54
- define_method("#{name}_defval") { defval }
55
- end
56
- end
57
-
58
- class_eval <<-EOD, __FILE__, __LINE__+1
59
- def #{name}
60
- if instance_variable_defined?(:@#{name}) then @#{name}
61
- else @#{name} = #{name}_defval
62
- end
63
- end
64
- EOD
65
- end
1
+ class Object
2
+ # call-seq:
3
+ # attribute :name => default_value
4
+ # attribute(:name) { default_value }
5
+ #
6
+ # In the first form, defines a read-write attribute
7
+ # named 'name' with default_value for default value.
8
+ # In the second form, the block is called if the attribute
9
+ # is read before it has been ever written, and its return
10
+ # value is used as default value.
11
+ def attribute(attr_def, &init) # :nodoc:
12
+ if Hash === attr_def
13
+ name, defval = attr_def.to_a.flatten
14
+ else
15
+ name = attr_def
16
+ end
17
+
18
+ class_eval do
19
+ attr_writer name
20
+ if !defval && init
21
+ define_method("#{name}_defval", &init)
22
+ else
23
+ define_method("#{name}_defval") { defval }
24
+ end
25
+ end
26
+
27
+ class_eval <<-EOD, __FILE__, __LINE__+1
28
+ def #{name}
29
+ if instance_variable_defined?(:@#{name}) then @#{name}
30
+ else @#{name} = #{name}_defval
31
+ end
32
+ end
33
+ EOD
66
34
  end
67
35
  end
68
36
 
@@ -1,20 +1 @@
1
- require 'utilrb/common'
2
- require 'utilrb/object/address'
3
-
4
- class Object
5
- if !Object.new.respond_to?(:singleton_class)
6
- # Returns the singleton class for this object.
7
- #
8
- # In Ruby 1.8, makes sure that the #superclass method of the singleton class
9
- # returns the object's class (instead of Class), as Ruby 1.9 does
10
- #
11
- # The first element of #ancestors on the returned singleton class is
12
- # the singleton class itself. A #singleton_instance accessor is also
13
- # defined, which returns the object instance the class is the singleton
14
- # of.
15
- def singleton_class
16
- class << self; self end
17
- end
18
- end
19
- end
20
-
1
+ puts "WARN: no need to require 'object/singleton_class' anymore, it is built-in since Ruby 1.9"
@@ -109,7 +109,8 @@ module Utilrb
109
109
  requested_op.include?(pkg.version <=> requested_version)
110
110
  end
111
111
  if !result
112
- raise NotFound.new(name), "no version of #{name} match #{version_spect}. Available versions are: #{candidates.map(&:raw_version).join(", ")}"
112
+ name = candidates.first.name
113
+ raise NotFound.new(name), "no version of #{name} match #{version_spec}. Available versions are: #{candidates.map(&:raw_version).join(", ")}"
113
114
  end
114
115
  result
115
116
  else
@@ -215,7 +216,7 @@ module Utilrb
215
216
 
216
217
  running_line = nil
217
218
  @file = file.map do |line|
218
- line.gsub! /\s*#.*$/, ''
219
+ line = line.gsub(/\s*#.*$/, '')
219
220
  line = line.strip
220
221
  next if line.empty?
221
222
 
@@ -260,14 +261,23 @@ module Utilrb
260
261
  raw_fields.each do |name, value|
261
262
  if SHELL_VARS.include?(name)
262
263
  value = Shellwords.shellsplit(value)
263
- value.map! do |v|
264
- expand_variables(v, variables, name)
264
+ resolved = Array.new
265
+ while !value.empty?
266
+ value = value.flat_map do |v|
267
+ expanded = expand_variables(v, variables, name)
268
+ if expanded == v
269
+ resolved << v
270
+ nil
271
+ else
272
+ Shellwords.shellsplit(expanded)
273
+ end
274
+ end.compact
265
275
  end
276
+ fields[name] = resolved
266
277
  else
267
- value = expand_variables(value, variables, name)
278
+ fields[name] = expand_variables(value, variables, name)
268
279
  end
269
280
 
270
- fields[name] = value
271
281
  end
272
282
 
273
283
  # Initialize the main flags
@@ -389,7 +399,7 @@ module Utilrb
389
399
  end
390
400
 
391
401
  def libs_only_other(static = false)
392
- @ldflags[static].find_all { |s| s !~ /^-[lL]/ }.join(" ")
402
+ @ldflags_with_requires[static].find_all { |s| s !~ /^-[lL]/ }.join(" ")
393
403
  end
394
404
 
395
405
  def method_missing(varname, *args, &proc) # :nodoc:
@@ -412,7 +422,7 @@ module Utilrb
412
422
  result = []
413
423
  each_pkgconfig_directory do |dir|
414
424
  path = File.join(dir, "#{name}.pc")
415
- if File.exists?(path)
425
+ if File.exist?(path)
416
426
  result << path
417
427
  end
418
428
  end
@@ -451,8 +461,8 @@ module Utilrb
451
461
  end
452
462
 
453
463
 
454
- FOUND_PATH_RX = /Scanning directory '(.*\/)((?:lib|share)\/.*)'$/
455
- NONEXISTENT_PATH_RX = /Cannot open directory '.*\/((?:lib|share)\/.*)' in package search path:.*/
464
+ FOUND_PATH_RX = /Scanning directory '(.*\/)((?:lib|lib64|share)\/.*)'$/
465
+ NONEXISTENT_PATH_RX = /Cannot open directory '.*\/((?:lib|lib64|share)\/.*)' in package search path:.*/
456
466
 
457
467
  # Returns the system-wide search path that is embedded in pkg-config
458
468
  def self.default_search_path
@@ -463,6 +473,7 @@ module Utilrb
463
473
  end
464
474
  return @default_search_path
465
475
  end
476
+ @default_search_path = nil
466
477
 
467
478
  # Returns the system-wide standard suffixes that should be appended to
468
479
  # new prefixes to find pkg-config files
@@ -1,7 +1,7 @@
1
1
  require 'socket'
2
2
 
3
3
  class TCPServer
4
- def bound_addr; Socket::getnameinfo(getsockname)[0] end
5
- def port; Socket::getnameinfo(getsockname)[1].to_i end
4
+ def bound_addr; Socket.unpack_sockaddr_in(getsockname)[1] end
5
+ def port; Socket.unpack_sockaddr_in(getsockname)[0] end
6
6
  end
7
7
 
data/lib/utilrb/spawn.rb CHANGED
@@ -47,7 +47,7 @@ module Utilrb
47
47
  Dir.chdir(workdir)
48
48
  end
49
49
  exec(*cmdline)
50
- rescue Exception => e
50
+ rescue Exception
51
51
  write.write("FAILED")
52
52
  end
53
53
  end
@@ -0,0 +1,65 @@
1
+ # simplecov must be loaded FIRST. Only the files required after it gets loaded
2
+ # will be profiled !!!
3
+ if ENV['TEST_ENABLE_COVERAGE'] != '0'
4
+ begin
5
+ require 'simplecov'
6
+ require 'coveralls'
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+ SimpleCov.start do
12
+ add_filter "/test/"
13
+ end
14
+ rescue LoadError
15
+ require 'utilrb'
16
+ Utilrb.warn "coverage is disabled because the 'simplecov' gem cannot be loaded"
17
+ rescue Exception => e
18
+ require 'utilrb'
19
+ Utilrb.warn "coverage is disabled: #{e.message}"
20
+ end
21
+ end
22
+
23
+ require 'utilrb'
24
+ require 'minitest/autorun'
25
+ require 'minitest/spec'
26
+
27
+ if ENV['TEST_ENABLE_PRY'] != '0'
28
+ begin
29
+ require 'pry'
30
+ rescue Exception
31
+ Utilrb.warn "debugging is disabled because the 'pry' gem cannot be loaded"
32
+ end
33
+ end
34
+
35
+ BASE_TEST_DIR=File.expand_path('../../test', File.dirname(__FILE__))
36
+
37
+ module Utilrb
38
+ # This module is the common setup for all tests
39
+ #
40
+ # It should be included in the toplevel describe blocks
41
+ #
42
+ # @example
43
+ # require 'dummyproject/test'
44
+ # describe Utilrb do
45
+ # include Utilrb::SelfTest
46
+ # end
47
+ #
48
+ module SelfTest
49
+ def setup
50
+ # Setup code for all the tests
51
+ end
52
+
53
+ def teardown
54
+ super
55
+ # Teardown code for all the tests
56
+ end
57
+ end
58
+ end
59
+
60
+ module Minitest
61
+ class Test
62
+ include Utilrb::SelfTest
63
+ end
64
+ end
65
+
@@ -492,7 +492,7 @@ module Utilrb
492
492
  end
493
493
  task.queued_at = Time.now
494
494
  @tasks_waiting << task
495
- if @waiting == 0 && @spawned < @max
495
+ if @waiting <= @tasks_waiting.size && @spawned < @max
496
496
  spawn_thread
497
497
  end
498
498
  @cond.signal
@@ -506,10 +506,8 @@ module Utilrb
506
506
  # @param [boolean] force Trim even if no thread is waiting.
507
507
  def trim (force = false)
508
508
  @mutex.synchronize do
509
- if (force || @waiting > 0) && @spawned - @trim_requests > @min
510
- @trim_requests += 1
511
- @cond.signal
512
- end
509
+ @trim_requests += 1
510
+ @cond.signal
513
511
  end
514
512
  self
515
513
  end
@@ -571,8 +569,10 @@ module Utilrb
571
569
  end
572
570
  break task unless task.is_a? Array
573
571
 
574
- if @trim_requests > 0
575
- @trim_requests -= 1
572
+ if @spawned > @min && (auto_trim || @trim_requests > 0)
573
+ if @trim_requests > 0
574
+ @trim_requests -= 1
575
+ end
576
576
  break
577
577
  end
578
578
  @waiting += 1
@@ -597,14 +597,12 @@ module Utilrb
597
597
  current_task.finalize # propagate state after it was deleted from the internal lists
598
598
  @callback_on_task_finished.call(current_task) if @callback_on_task_finished
599
599
  end
600
- trim if auto_trim
601
600
  end
602
601
 
603
- # we do not have to lock here
604
- # because spawn_thread must be called from
605
- # a synchronized block
606
- @spawned -= 1
607
- @workers.delete thread
602
+ @mutex.synchronize do
603
+ @spawned -= 1
604
+ @workers.delete thread
605
+ end
608
606
  end
609
607
  @spawned += 1
610
608
  @workers << thread
@@ -1,5 +1,9 @@
1
1
  module Utilrb
2
2
  module Timepoints
3
+ def timepoints
4
+ @timepoints || Array.new
5
+ end
6
+
3
7
  def clear_timepoints
4
8
  @timepoints ||= Array.new
5
9
  @timepoints.clear
@@ -18,6 +22,17 @@ module Utilrb
18
22
  end
19
23
  result
20
24
  end
25
+
26
+ def merge_timepoints(other)
27
+ data =
28
+ if other.respond_to?(:to_ary)
29
+ other.to_ary
30
+ else
31
+ other.timepoints
32
+ end
33
+ @timepoints = (timepoints + data).sort_by(&:first)
34
+ self
35
+ end
21
36
  end
22
37
  end
23
38
 
@@ -9,7 +9,16 @@ Utilrb.require_ext("ValueSet") do
9
9
  alias :- :difference
10
10
  include Enumerable
11
11
 
12
- def to_s
12
+ def substract(other_set)
13
+ difference!(other_set.to_value_set)
14
+ end
15
+
16
+ def add(value)
17
+ insert(value)
18
+ self
19
+ end
20
+
21
+ def to_s
13
22
  elements = EnumerableToString.to_s_helper(self, '{', '}') do |obj|
14
23
  obj.to_s
15
24
  end
@@ -0,0 +1,4 @@
1
+ module Utilrb
2
+ VERSION = "2.1.0.rc1"
3
+ end
4
+
@@ -1,17 +1,16 @@
1
- require 'utilrb/common'
1
+ require 'weakref'
2
2
 
3
- Utilrb.require_ext("Utilrb::WeakRef") do
4
- module Utilrb
5
- class WeakRef
6
- def initialize(obj)
7
- if obj.kind_of?(WeakRef)
8
- raise ArgumentError, "cannot create a weakref of a weakref"
9
- end
10
- unless WeakRef.refcount(obj)
11
- ObjectSpace.define_finalizer(obj, self.class.method(:do_object_finalize))
12
- end
13
- do_initialize(obj)
3
+ module Utilrb
4
+ class WeakRef < ::WeakRef
5
+ def initialize(obj)
6
+ if obj.kind_of?(::WeakRef)
7
+ raise ArgumentError, "cannot create a weakref of a weakref"
14
8
  end
9
+ super
10
+ end
11
+
12
+ def get
13
+ __getobj__
15
14
  end
16
15
  end
17
16
  end
data/lib/utilrb/yard.rb CHANGED
@@ -2,117 +2,6 @@ require 'pp'
2
2
  module Utilrb
3
3
  module YARD
4
4
  include ::YARD
5
- class InheritedAttributeHandler < YARD::Handlers::Ruby::AttributeHandler
6
- handles method_call(:inherited_attribute)
7
- namespace_only
8
-
9
- def self.process(handler, name, attr_name, is_map, key_name = nil, return_type = nil)
10
- end
11
-
12
- def process
13
- name = statement.parameters[0].jump(:tstring_content, :ident).source
14
- if statement.parameters.size == 4
15
- attr_name = statement.parameters[1].jump(:tstring_content, :ident).source
16
- else
17
- attr_name = name
18
- end
19
- options = statement.parameters.jump(:assoc)
20
-
21
- is_map = false
22
- if options != statement.parameters
23
- key = options[0].jump(:ident).source
24
- value = options[1].jump(:ident).source
25
- if key == "map" && value == "true"
26
- is_map = true
27
- end
28
- end
29
-
30
- key_type, value_type = nil
31
-
32
- object = YARD::CodeObjects::MethodObject.new(namespace, attr_name, scope) do |o|
33
- o.dynamic = true
34
- o.aliases << "self_#{name}"
35
- end
36
- register(object)
37
- key_name ||=
38
- if object.docstring.has_tag?('key_name')
39
- object.docstring.tag('key_name').text
40
- else
41
- 'key'
42
- end
43
- return_type ||=
44
- if object.docstring.has_tag?('return')
45
- object.docstring.tag('return').types.first
46
- elsif is_map
47
- 'Hash<Object,Object>'
48
- else
49
- 'Array<Object>'
50
- end
51
- if return_type =~ /^\w+\<(.*)\>$/
52
- if is_map
53
- key_type, value_type = $1.split(',')
54
- else
55
- value_type = $1
56
- end
57
- else
58
- key_type = "Object"
59
- value_type = "Object"
60
- end
61
-
62
- object = YARD::CodeObjects::MethodObject.new(namespace, "all_#{name}", scope)
63
- object.dynamic = true
64
- register(object)
65
- object.docstring.replace("The union, along the class hierarchy, of all the values stored in #{name}\n@return [Array<#{value_type}>]")
66
-
67
- if is_map
68
- object = YARD::CodeObjects::MethodObject.new(namespace, "find_#{name}", scope)
69
- object.dynamic = true
70
- register(object)
71
- object.parameters << [key_name]
72
- object.docstring.replace("
73
- Looks for objects registered in #{name} under the given key, and returns the first one in the ancestor chain
74
- (i.e. the one tha thas been registered in the most specialized class)
75
-
76
- @return [#{value_type},nil] the found object, or nil if none is registered under that key")
77
-
78
- object = YARD::CodeObjects::MethodObject.new(namespace, "has_#{name}?", scope)
79
- object.dynamic = true
80
- register(object)
81
- object.parameters << [key_name]
82
- object.docstring.replace("Returns true if an object is registered in #{name} anywhere in the class hierarchy\n@return [Boolean]")
83
- object.signature = "def has_#{name}?(key)"
84
-
85
- object = YARD::CodeObjects::MethodObject.new(namespace, "each_#{name}", scope)
86
- object.dynamic = true
87
- register(object)
88
- object.parameters << [key_name, "nil"] << ["uniq", "true"]
89
- object.docstring.replace("
90
- @overload each_#{name}(#{key_name}, uniq = true)
91
- Enumerates all objects registered in #{name} under the given key
92
- @yield [element]
93
- @yieldparam [#{value_type}] element
94
- @overload each_#{name}(nil, uniq = true)
95
- Enumerates all objects registered in #{name}
96
- @yield [#{key_name}, element]
97
- @yieldparam [#{key_type}] #{key_name}
98
- @yieldparam [#{value_type}] element
99
- ")
100
- else
101
- object = YARD::CodeObjects::MethodObject.new(namespace, "each_#{name}", scope)
102
- object.dynamic = true
103
- register(object)
104
- object.docstring.replace("Enumerates all objects registered in #{name}\n@return []\n@yield [element]\n@yieldparam [#{value_type}] element")
105
- end
106
-
107
- if is_map
108
- return key_type, value_type
109
- else
110
- return value_type
111
- end
112
- end
113
- end
114
- YARD::Tags::Library.define_tag("Key for inherited_attribute(_, :map => true)", :key_name)
115
-
116
5
  class AttrEnumerableHandler < YARD::Handlers::Ruby::AttributeHandler
117
6
  handles method_call(:attr_enumerable)
118
7
  namespace_only
data/lib/utilrb.rb CHANGED
@@ -1,2 +1,7 @@
1
1
  require 'utilrb/kernel/require'
2
- require_dir(__FILE__, /yard|doc|rake/)
2
+ require 'utilrb/logger'
3
+ module Utilrb
4
+ extend Logger::Root('Utilrb', Logger::WARN)
5
+ end
6
+
7
+ require_dir(__FILE__, /yard|doc|rake|test/)
@@ -0,0 +1 @@
1
+ require 'utilrb/yard'