utilrb 2.0.2.b2 → 2.1.0.rc1
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.
- checksums.yaml +4 -4
- data/.boring +40 -0
- data/.gitignore +13 -0
- data/.travis.yml +5 -0
- data/CMakeLists.txt +18 -0
- data/Gemfile +3 -0
- data/Makefile +8 -0
- data/Manifest.txt +0 -8
- data/{README.rd → README.md} +11 -7
- data/Rakefile +16 -63
- data/benchmarks/validate_options.rb +79 -0
- data/ext/utilrb/extconf.rb +1 -17
- data/ext/utilrb/utilrb.cc +0 -23
- data/lib/utilrb/column_formatter.rb +8 -5
- data/lib/utilrb/common.rb +1 -6
- data/lib/utilrb/enumerable/uniq.rb +2 -8
- data/lib/utilrb/event_loop.rb +5 -10
- data/lib/utilrb/kernel/load_dsl_file.rb +1 -2
- data/lib/utilrb/kernel/options.rb +25 -29
- data/lib/utilrb/logger/hierarchy.rb +0 -1
- data/lib/utilrb/logger/io.rb +3 -3
- data/lib/utilrb/logger/root.rb +12 -6
- data/lib/utilrb/module/ancestor_p.rb +0 -12
- data/lib/utilrb/module/is_singleton.rb +6 -0
- data/lib/utilrb/module/singleton_class_p.rb +14 -0
- data/lib/utilrb/object/attribute.rb +33 -65
- data/lib/utilrb/object/singleton_class.rb +1 -20
- data/lib/utilrb/pkgconfig.rb +21 -10
- data/lib/utilrb/socket/tcp_server.rb +2 -2
- data/lib/utilrb/spawn.rb +1 -1
- data/lib/utilrb/test.rb +65 -0
- data/lib/utilrb/thread_pool.rb +11 -13
- data/lib/utilrb/timepoints.rb +15 -0
- data/lib/utilrb/value_set.rb +10 -1
- data/lib/utilrb/version.rb +4 -0
- data/lib/utilrb/weakref.rb +11 -12
- data/lib/utilrb/yard.rb +0 -111
- data/lib/utilrb.rb +6 -1
- data/lib/yard-utilrb.rb +1 -0
- data/manifest.xml +19 -0
- data/package.xml +29 -0
- data/utilrb.gemspec +27 -0
- metadata +56 -107
- data/ext/utilrb/proc.c +0 -39
- data/ext/utilrb/readline.c +0 -52
- data/ext/utilrb/weakref.cc +0 -143
- data/lib/utilrb/models/inherited_enumerable.rb +0 -341
- data/lib/utilrb/models/registration.rb +0 -115
- data/lib/utilrb/module/inherited_enumerable.rb +0 -6
- data/lib/utilrb/objectstats.rb +0 -193
- data/lib/utilrb/ruby_object_graph.rb +0 -384
- data/test/data/test_pkgconfig.pc +0 -9
- data/test/data/test_pkgconfig_empty.pc +0 -10
- data/test/test_array.rb +0 -15
- data/test/test_config.rb +0 -4
- data/test/test_dir.rb +0 -22
- data/test/test_enumerable.rb +0 -119
- data/test/test_event_loop.rb +0 -407
- data/test/test_exception.rb +0 -38
- data/test/test_gc.rb +0 -34
- data/test/test_hash.rb +0 -102
- data/test/test_kernel.rb +0 -300
- data/test/test_logger.rb +0 -204
- data/test/test_misc.rb +0 -42
- data/test/test_models.rb +0 -212
- data/test/test_module.rb +0 -126
- data/test/test_object.rb +0 -77
- data/test/test_objectstats.rb +0 -26
- data/test/test_pkgconfig.rb +0 -84
- data/test/test_proc.rb +0 -31
- data/test/test_set.rb +0 -19
- data/test/test_thread_pool.rb +0 -409
- data/test/test_time.rb +0 -47
- data/test/test_unbound_method.rb +0 -23
- data/test/test_weakref.rb +0 -81
data/lib/utilrb/logger/io.rb
CHANGED
@@ -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
|
|
data/lib/utilrb/logger/root.rb
CHANGED
@@ -41,9 +41,15 @@ class Logger
|
|
41
41
|
#
|
42
42
|
def self.Root(progname, base_level, &block)
|
43
43
|
begin
|
44
|
-
|
45
|
-
|
46
|
-
|
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,
|
55
|
-
console.color("#{
|
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,
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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 '
|
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"
|
data/lib/utilrb/pkgconfig.rb
CHANGED
@@ -109,7 +109,8 @@ module Utilrb
|
|
109
109
|
requested_op.include?(pkg.version <=> requested_version)
|
110
110
|
end
|
111
111
|
if !result
|
112
|
-
|
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
|
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
|
-
|
264
|
-
|
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
|
-
|
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
|
-
@
|
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.
|
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
|
5
|
-
def port; Socket
|
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
data/lib/utilrb/test.rb
ADDED
@@ -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
|
+
|
data/lib/utilrb/thread_pool.rb
CHANGED
@@ -492,7 +492,7 @@ module Utilrb
|
|
492
492
|
end
|
493
493
|
task.queued_at = Time.now
|
494
494
|
@tasks_waiting << task
|
495
|
-
if @waiting
|
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
|
-
|
510
|
-
|
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
|
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
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
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
|
data/lib/utilrb/timepoints.rb
CHANGED
@@ -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
|
|
data/lib/utilrb/value_set.rb
CHANGED
@@ -9,7 +9,16 @@ Utilrb.require_ext("ValueSet") do
|
|
9
9
|
alias :- :difference
|
10
10
|
include Enumerable
|
11
11
|
|
12
|
-
|
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
|
data/lib/utilrb/weakref.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'weakref'
|
2
2
|
|
3
|
-
Utilrb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
data/lib/yard-utilrb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'utilrb/yard'
|