utilrb 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +12 -0
- data/Rakefile +4 -1
- data/lib/utilrb/common.rb +1 -1
- data/lib/utilrb/doc/rake.rb +51 -0
- data/lib/utilrb/hash/map_key.rb +13 -0
- data/lib/utilrb/hash/map_value.rb +13 -0
- data/lib/utilrb/logger/indent.rb +40 -0
- data/lib/utilrb/logger/log_pp.rb +48 -0
- data/lib/utilrb/logger/root.rb +65 -0
- data/lib/utilrb/module/dsl_attribute.rb +65 -0
- data/lib/utilrb/rake_common.rb +28 -0
- data/lib/utilrb/spawn.rb +60 -0
- data/lib/utilrb/timepoints.rb +23 -0
- data/lib/utilrb/yard.rb +161 -0
- metadata +28 -17
data/Manifest.txt
CHANGED
@@ -22,6 +22,7 @@ lib/utilrb/configsearch.rb
|
|
22
22
|
lib/utilrb/configsearch/configuration_finder.rb
|
23
23
|
lib/utilrb/dir.rb
|
24
24
|
lib/utilrb/dir/empty.rb
|
25
|
+
lib/utilrb/doc/rake.rb
|
25
26
|
lib/utilrb/enumerable.rb
|
26
27
|
lib/utilrb/enumerable/null.rb
|
27
28
|
lib/utilrb/enumerable/random_element.rb
|
@@ -33,6 +34,8 @@ lib/utilrb/exception/full_message.rb
|
|
33
34
|
lib/utilrb/gc.rb
|
34
35
|
lib/utilrb/gc/force.rb
|
35
36
|
lib/utilrb/hash.rb
|
37
|
+
lib/utilrb/hash/map_key.rb
|
38
|
+
lib/utilrb/hash/map_value.rb
|
36
39
|
lib/utilrb/hash/recursive_merge.rb
|
37
40
|
lib/utilrb/hash/slice.rb
|
38
41
|
lib/utilrb/hash/to_s.rb
|
@@ -48,7 +51,10 @@ lib/utilrb/kernel/with_module.rb
|
|
48
51
|
lib/utilrb/logger.rb
|
49
52
|
lib/utilrb/logger/forward.rb
|
50
53
|
lib/utilrb/logger/hierarchy.rb
|
54
|
+
lib/utilrb/logger/indent.rb
|
51
55
|
lib/utilrb/logger/io.rb
|
56
|
+
lib/utilrb/logger/log_pp.rb
|
57
|
+
lib/utilrb/logger/root.rb
|
52
58
|
lib/utilrb/marshal/load_with_missing_constants.rb
|
53
59
|
lib/utilrb/module.rb
|
54
60
|
lib/utilrb/module/ancestor_p.rb
|
@@ -58,6 +64,7 @@ lib/utilrb/module/cached_enum.rb
|
|
58
64
|
lib/utilrb/module/const_defined_here_p.rb
|
59
65
|
lib/utilrb/module/define_method.rb
|
60
66
|
lib/utilrb/module/define_or_reuse.rb
|
67
|
+
lib/utilrb/module/dsl_attribute.rb
|
61
68
|
lib/utilrb/module/include.rb
|
62
69
|
lib/utilrb/module/inherited_enumerable.rb
|
63
70
|
lib/utilrb/object.rb
|
@@ -67,17 +74,21 @@ lib/utilrb/object/scoped_eval.rb
|
|
67
74
|
lib/utilrb/object/singleton_class.rb
|
68
75
|
lib/utilrb/objectstats.rb
|
69
76
|
lib/utilrb/pkgconfig.rb
|
77
|
+
lib/utilrb/rake_common.rb
|
70
78
|
lib/utilrb/set.rb
|
71
79
|
lib/utilrb/set/to_s.rb
|
72
80
|
lib/utilrb/socket/tcp_server.rb
|
73
81
|
lib/utilrb/socket/tcp_socket.rb
|
82
|
+
lib/utilrb/spawn.rb
|
74
83
|
lib/utilrb/symbol/to_str.rb
|
75
84
|
lib/utilrb/time.rb
|
76
85
|
lib/utilrb/time/to_hms.rb
|
86
|
+
lib/utilrb/timepoints.rb
|
77
87
|
lib/utilrb/unbound_method.rb
|
78
88
|
lib/utilrb/unbound_method/call.rb
|
79
89
|
lib/utilrb/value_set.rb
|
80
90
|
lib/utilrb/weakref.rb
|
91
|
+
lib/utilrb/yard.rb
|
81
92
|
patches/gc_live_objects.patch
|
82
93
|
test/data/test_pkgconfig.pc
|
83
94
|
test/data/test_pkgconfig_empty.pc
|
@@ -89,6 +100,7 @@ test/test_exception.rb
|
|
89
100
|
test/test_gc.rb
|
90
101
|
test/test_hash.rb
|
91
102
|
test/test_kernel.rb
|
103
|
+
test/test_logger.rb
|
92
104
|
test/test_misc.rb
|
93
105
|
test/test_module.rb
|
94
106
|
test/test_object.rb
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require './lib/utilrb/common'
|
3
3
|
require './lib/utilrb/rake_common'
|
4
|
+
require './lib/utilrb/doc/rake'
|
4
5
|
|
5
6
|
Utilrb::Rake.hoe do
|
6
7
|
hoe_spec = Hoe.spec 'utilrb' do
|
@@ -17,11 +18,13 @@ Utilrb::Rake.hoe do
|
|
17
18
|
end
|
18
19
|
hoe_spec.spec.extensions << 'ext/extconf.rb'
|
19
20
|
Rake.clear_tasks(/^default$/)
|
20
|
-
Rake.clear_tasks(/
|
21
|
+
Rake.clear_tasks(/doc/)
|
21
22
|
end
|
22
23
|
|
23
24
|
task :default => :setup
|
24
25
|
|
26
|
+
Utilrb.doc
|
27
|
+
|
25
28
|
desc "builds Utilrb's C extension"
|
26
29
|
task :setup do
|
27
30
|
Dir.chdir("ext") do
|
data/lib/utilrb/common.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'utilrb/kernel/options'
|
2
|
+
|
3
|
+
module Utilrb
|
4
|
+
DOC_MODE =
|
5
|
+
begin
|
6
|
+
require 'yard'
|
7
|
+
require 'yard/rake/yardoc_task'
|
8
|
+
'yard'
|
9
|
+
rescue LoadError
|
10
|
+
begin
|
11
|
+
require 'rdoc/task'
|
12
|
+
'rdoc-new'
|
13
|
+
rescue LoadError
|
14
|
+
begin
|
15
|
+
require 'rake/rdoctask'
|
16
|
+
'rdoc-old'
|
17
|
+
rescue LoadError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.doc(target = 'docs', options = Hash.new)
|
23
|
+
options = Kernel.validate_options options,
|
24
|
+
:include => [File.join(Dir.pwd, 'lib', '**'), File.join(Dir.pwd, 'ext', '**')],
|
25
|
+
:exclude => [],
|
26
|
+
:target_dir => 'doc',
|
27
|
+
:title => '',
|
28
|
+
:plugins => []
|
29
|
+
|
30
|
+
case DOC_MODE
|
31
|
+
when 'yard'
|
32
|
+
task = YARD::Rake::YardocTask.new(target)
|
33
|
+
task.files.concat(options[:include])
|
34
|
+
task.options << '--title' << options[:title] << '--output-dir' << options[:target_dir]
|
35
|
+
options[:plugins].each do |plugin_name|
|
36
|
+
require "#{plugin_name}/yard"
|
37
|
+
end
|
38
|
+
when /rdoc/
|
39
|
+
klass = if DOC_MODE == 'rdoc-new'
|
40
|
+
RDoc::Task
|
41
|
+
else
|
42
|
+
Rake::RdocTask
|
43
|
+
end
|
44
|
+
task = klass.new(target)
|
45
|
+
task.rdoc_files.include(*options[:include])
|
46
|
+
task.rdoc_files.exclude(*options[:exclude])
|
47
|
+
task.title = options[:title]
|
48
|
+
task.rdoc_dir = File.expand_path(options[:target_dir])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'utilrb/object/attribute'
|
2
|
+
class Logger
|
3
|
+
attribute(:nest_size) { 0 }
|
4
|
+
def nest_size=(new_value)
|
5
|
+
@nest_string = nil
|
6
|
+
@nest_size = new_value
|
7
|
+
end
|
8
|
+
|
9
|
+
def nest(size, level = nil)
|
10
|
+
if level
|
11
|
+
send(level) do
|
12
|
+
nest(size) do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
return
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if block_given?
|
20
|
+
begin
|
21
|
+
current = self.nest_size
|
22
|
+
self.nest_size += size
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
self.nest_size = current
|
26
|
+
end
|
27
|
+
else
|
28
|
+
self.nest_size += size
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def format_message(severity, datetime, progname, msg)
|
33
|
+
if !@nest_string
|
34
|
+
@nest_string = " " * self.nest_size
|
35
|
+
end
|
36
|
+
msg = "#{@nest_string}#{msg}"
|
37
|
+
(@formatter || @default_formatter).call(severity, datetime, progname, msg)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
begin
|
2
|
+
require "highline"
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'utilrb/exception/full_message'
|
7
|
+
class Logger
|
8
|
+
def self.pp_to_array(object)
|
9
|
+
message =
|
10
|
+
begin
|
11
|
+
PP.pp(object, "")
|
12
|
+
rescue Exception => formatting_error
|
13
|
+
begin
|
14
|
+
"error formatting object using pretty-printing\n" +
|
15
|
+
object.to_s +
|
16
|
+
"\nplease report the formatting error: \n" +
|
17
|
+
formatting_error.full_message
|
18
|
+
rescue Exception => formatting_error
|
19
|
+
"\nerror formatting object using pretty-printing\n" +
|
20
|
+
formatting_error.full_message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
message.split("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? HighLine
|
28
|
+
def color(*args)
|
29
|
+
@color_generator ||= HighLine.new
|
30
|
+
@color_generator.color(*args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_pp(level, object, *first_line_format)
|
35
|
+
send(level) do
|
36
|
+
first_line = !first_line_format.empty? && defined?(HighLine)
|
37
|
+
Logger.pp_to_array(object).each do |line|
|
38
|
+
if first_line
|
39
|
+
line = color(line, *first_line_format)
|
40
|
+
first_line = false
|
41
|
+
end
|
42
|
+
send(level, line)
|
43
|
+
end
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Logger
|
2
|
+
HAS_COLOR =
|
3
|
+
begin
|
4
|
+
require 'highline'
|
5
|
+
@console = HighLine.new
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
LEVEL_TO_COLOR =
|
10
|
+
{ 'DEBUG' => [],
|
11
|
+
'INFO' => [],
|
12
|
+
'WARN' => [:magenta],
|
13
|
+
'ERROR' => [:red],
|
14
|
+
'FATAL' => [:red, :bold] }
|
15
|
+
|
16
|
+
# Defines a logger on a module, allowing to use that module as a root in a
|
17
|
+
# hierarchy (i.e. having submodules use the Logger::Hierarchy support)
|
18
|
+
#
|
19
|
+
# +progname+ is used as the logger's program name
|
20
|
+
#
|
21
|
+
# +base_level+ is the level at which the logger is initialized
|
22
|
+
#
|
23
|
+
# If a block is given, it will be provided the message severity, time,
|
24
|
+
# program name and text and should return the formatted message.
|
25
|
+
#
|
26
|
+
# This method creates a +logger+ attribute in which the module can be
|
27
|
+
# accessed. Moreover, it includes Logger::Forward, which allows to access
|
28
|
+
# the logger's output methods on the module directly
|
29
|
+
#
|
30
|
+
# Example:
|
31
|
+
#
|
32
|
+
# module MyModule
|
33
|
+
# extend Logger.Root('MyModule', :WARN)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# MyModule.info "text"
|
37
|
+
# MyModule.warn "warntext"
|
38
|
+
def self.Root(progname, base_level, &block)
|
39
|
+
console = @console
|
40
|
+
formatter =
|
41
|
+
if block then lambda(&block)
|
42
|
+
elsif HAS_COLOR
|
43
|
+
lambda do |severity, time, progname, msg|
|
44
|
+
console.color("#{progname}[#{severity}]: #{msg}\n", *LEVEL_TO_COLOR[severity])
|
45
|
+
end
|
46
|
+
else lambda { |severity, time, progname, msg| "#{progname}[#{severity}]: #{msg}\n" }
|
47
|
+
end
|
48
|
+
|
49
|
+
Module.new do
|
50
|
+
include Logger::Forward
|
51
|
+
|
52
|
+
singleton = (class << self; self end)
|
53
|
+
singleton.send(:define_method, :extended) do |mod|
|
54
|
+
logger = Logger.new(STDOUT)
|
55
|
+
logger.level = base_level
|
56
|
+
logger.progname = progname
|
57
|
+
logger.formatter = formatter
|
58
|
+
mod.instance_variable_set(:@logger, logger)
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_accessor :logger
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Module
|
2
|
+
# call-seq:
|
3
|
+
# dsl_attribute(name)
|
4
|
+
# dsl_attribute(name) { |value| ... }
|
5
|
+
#
|
6
|
+
# This defines a +name+ instance method on the given class which accepts zero or one argument
|
7
|
+
#
|
8
|
+
# Without any argument, it acts as a getter for the +@name+ attribute. With
|
9
|
+
# one argument, it acts instead as a setter for the same attribute and
|
10
|
+
# returns self. If a block has been given to +dsl_attribute+, any new value
|
11
|
+
# is passed to the block, whose return value is actually saved in the
|
12
|
+
# instance variable. This block can therefore both filter the value
|
13
|
+
# (convert it to a desired form) and validate it.
|
14
|
+
#
|
15
|
+
# The goal of this method is to have a nicer way to handle attribute in DSLs: instead
|
16
|
+
# of
|
17
|
+
#
|
18
|
+
# model = create_model do
|
19
|
+
# self.my_model_attribute = 'bla'
|
20
|
+
#
|
21
|
+
# if (my_model_attribute)
|
22
|
+
# <do something>
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# (or worse, using set_ and get_ prefixes), we can do
|
27
|
+
#
|
28
|
+
# model = create_model do
|
29
|
+
# my_model_attribute 'bla', arg0, arg1, ...
|
30
|
+
#
|
31
|
+
# if (my_model_attribute)
|
32
|
+
# <do something>
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
def dsl_attribute(name, &filter_block)
|
37
|
+
class_eval do
|
38
|
+
if filter_block
|
39
|
+
define_method("__dsl_attribute__#{name}__filter__", &filter_block)
|
40
|
+
end
|
41
|
+
|
42
|
+
define_method(name) do |*value|
|
43
|
+
if value.empty?
|
44
|
+
instance_variable_get("@#{name}")
|
45
|
+
elsif filter_block
|
46
|
+
if filter_block.arity >= 0 && value.size != filter_block.arity
|
47
|
+
raise ArgumentError, "too much arguments. Got #{value.size}, expected #{filter_block.arity}"
|
48
|
+
end
|
49
|
+
|
50
|
+
filtered_value = send("__dsl_attribute__#{name}__filter__", *value)
|
51
|
+
instance_variable_set("@#{name}", filtered_value)
|
52
|
+
self
|
53
|
+
else
|
54
|
+
if value.size == 1
|
55
|
+
instance_variable_set("@#{name}", value.first)
|
56
|
+
else
|
57
|
+
instance_variable_set("@#{name}", value)
|
58
|
+
end
|
59
|
+
self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Utilrb
|
2
|
+
module Rake
|
3
|
+
def self.hoe
|
4
|
+
require 'hoe'
|
5
|
+
yield
|
6
|
+
|
7
|
+
rescue LoadError => e
|
8
|
+
STDERR.puts "INFO: cannot load the Hoe gem. Distribution is disabled"
|
9
|
+
STDERR.puts "INFO: error message is: #{e.message}"
|
10
|
+
rescue Exception => e
|
11
|
+
STDERR.puts "INFO: cannot load the Hoe gem, or Hoe fails. Distribution is disabled"
|
12
|
+
STDERR.puts "INFO: error message is: #{e.message}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.rdoc
|
16
|
+
require 'rdoc/task'
|
17
|
+
yield
|
18
|
+
|
19
|
+
rescue LoadError => e
|
20
|
+
STDERR.puts "INFO: cannot load RDoc, Documentation generation is disabled"
|
21
|
+
STDERR.puts "INFO: error message is: #{e.message}"
|
22
|
+
rescue Exception => e
|
23
|
+
STDERR.puts "INFO: cannot load the RDoc gem, or RDoc failed to load. Documentation generation is disabled"
|
24
|
+
STDERR.puts "INFO: error message is: #{e.message}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/utilrb/spawn.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Utilrb
|
2
|
+
class SpawnFailed < RuntimeError; end
|
3
|
+
def self.spawn(*cmdline)
|
4
|
+
options =
|
5
|
+
if cmdline.last.kind_of?(Hash)
|
6
|
+
cmdline.pop
|
7
|
+
else Hash.new
|
8
|
+
end
|
9
|
+
|
10
|
+
options = Kernel.validate_options options, :redirect => nil,
|
11
|
+
:working_directory => nil,
|
12
|
+
:nice => nil
|
13
|
+
|
14
|
+
output = options[:redirect]
|
15
|
+
workdir = options[:working_directory]
|
16
|
+
|
17
|
+
read, write = IO.pipe
|
18
|
+
pid = fork do
|
19
|
+
if output
|
20
|
+
if !output.kind_of?(IO)
|
21
|
+
output_file_name = output.
|
22
|
+
gsub('%p', ::Process.pid.to_s)
|
23
|
+
if workdir
|
24
|
+
output_file_name = File.expand_path(output_file_name, workdir)
|
25
|
+
end
|
26
|
+
output = File.open(output, 'a')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if output
|
31
|
+
STDERR.reopen(output)
|
32
|
+
STDOUT.reopen(output)
|
33
|
+
end
|
34
|
+
|
35
|
+
read.close
|
36
|
+
write.sync = true
|
37
|
+
write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
38
|
+
::Process.setpgrp
|
39
|
+
if options[:nice]
|
40
|
+
Process.setpriority(Process::PRIO_PROCESS, 0, options[:nice])
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
if workdir
|
45
|
+
Dir.chdir(workdir)
|
46
|
+
end
|
47
|
+
exec(*cmdline)
|
48
|
+
rescue Exception => e
|
49
|
+
write.write("FAILED")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
write.close
|
54
|
+
if read.read == "FAILED"
|
55
|
+
raise SpawnFailed, "cannot start #{cmdline.inspect}"
|
56
|
+
end
|
57
|
+
pid
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Utilrb
|
2
|
+
module Timepoints
|
3
|
+
def clear_timepoints
|
4
|
+
@timepoints ||= Array.new
|
5
|
+
@timepoints.clear
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_timepoint(*names)
|
9
|
+
@timepoints ||= Array.new
|
10
|
+
@timepoints << [Time.now, names]
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_timepoints
|
14
|
+
result = []
|
15
|
+
@timepoints.inject(@timepoints.first.first) do |last_t, (t, name)|
|
16
|
+
result << name + [t - last_t]
|
17
|
+
t
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/utilrb/yard.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'pp'
|
2
|
+
module Utilrb
|
3
|
+
module YARD
|
4
|
+
include ::YARD
|
5
|
+
class InheritedEnumerableHandler < YARD::Handlers::Ruby::AttributeHandler
|
6
|
+
handles method_call(:inherited_enumerable)
|
7
|
+
namespace_only
|
8
|
+
|
9
|
+
def self.process(handler, name, attr_name, is_map)
|
10
|
+
handler.send(:push_state, :scope => :class) do
|
11
|
+
namespace = handler.send(:namespace)
|
12
|
+
scope = handler.send(:scope)
|
13
|
+
|
14
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, attr_name, scope) do |o|
|
15
|
+
o.dynamic = true
|
16
|
+
o.aliases << "self_#{name}"
|
17
|
+
end
|
18
|
+
handler.send(:register, object)
|
19
|
+
key_name ||=
|
20
|
+
if object.docstring.has_tag?('key_name')
|
21
|
+
object.docstring.tag('key_name').text
|
22
|
+
else
|
23
|
+
'key'
|
24
|
+
end
|
25
|
+
return_type ||=
|
26
|
+
if object.docstring.has_tag?('return')
|
27
|
+
object.docstring.tag('return').types.first
|
28
|
+
elsif is_map
|
29
|
+
'Hash<Object,Object>'
|
30
|
+
else
|
31
|
+
'Array<Object>'
|
32
|
+
end
|
33
|
+
if return_type =~ /^\w+\<(.*)\>$/
|
34
|
+
if is_map
|
35
|
+
key_type, value_type = $1.split(',')
|
36
|
+
else
|
37
|
+
value_type = $1
|
38
|
+
end
|
39
|
+
else
|
40
|
+
key_type = "Object"
|
41
|
+
value_type = "Object"
|
42
|
+
end
|
43
|
+
|
44
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "all_#{name}", scope)
|
45
|
+
object.dynamic = true
|
46
|
+
handler.send(:register, object)
|
47
|
+
object.docstring.replace("The union, along the class hierarchy, of all the values stored in #{name}\n@return [Array<#{value_type}>]")
|
48
|
+
|
49
|
+
if is_map
|
50
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "find_#{name}", scope)
|
51
|
+
object.dynamic = true
|
52
|
+
handler.send(:register, object)
|
53
|
+
object.parameters << [key_name]
|
54
|
+
object.docstring.replace("Looks for objects registered in #{name} under the given key, and returns the first one in the ancestor chain (i.e. the one tha thas been registered in the most specialized class)\n@return [#{value_type},nil] the found object, or nil if none is registered under that key")
|
55
|
+
|
56
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "has_#{name}?", scope)
|
57
|
+
object.dynamic = true
|
58
|
+
handler.send(:register, object)
|
59
|
+
object.parameters << [key_name]
|
60
|
+
object.docstring.replace("Returns true if an object is registered in #{name} anywhere in the class hierarchy\n@return [Boolean]")
|
61
|
+
object.signature = "def has_#{name}?(key)"
|
62
|
+
|
63
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "each_#{name}", scope)
|
64
|
+
object.dynamic = true
|
65
|
+
handler.send(:register, object)
|
66
|
+
object.parameters << [key_name, "nil"] << ["uniq", "true"]
|
67
|
+
object.docstring.replace("
|
68
|
+
@overload each_#{name}(#{key_name}, uniq = true)
|
69
|
+
Enumerates all objects registered in #{name} under the given key
|
70
|
+
@yield [element]
|
71
|
+
@yieldparam [#{value_type}] element
|
72
|
+
@overload each_#{name}(nil, uniq = true)
|
73
|
+
Enumerates all objects registered in #{name}
|
74
|
+
@yield [#{key_name}, element]
|
75
|
+
@yieldparam [#{key_type}] #{key_name}
|
76
|
+
@yieldparam [#{value_type}] element
|
77
|
+
")
|
78
|
+
else
|
79
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "each_#{name}", scope)
|
80
|
+
object.dynamic = true
|
81
|
+
handler.send(:register, object)
|
82
|
+
object.docstring.replace("Enumerates all objects registered in #{name}\n@return []\n@yield [element]\n@yieldparam [#{value_type}] element")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def process
|
88
|
+
name = statement.parameters[0].jump(:tstring_content, :ident).source
|
89
|
+
if statement.parameters.size == 4
|
90
|
+
attr_name = statement.parameters[1].jump(:tstring_content, :ident).source
|
91
|
+
else
|
92
|
+
attr_name = name
|
93
|
+
end
|
94
|
+
options = statement.parameters.jump(:assoc)
|
95
|
+
|
96
|
+
is_map = false
|
97
|
+
if options != statement.parameters
|
98
|
+
key = options[0].jump(:ident).source
|
99
|
+
value = options[1].jump(:ident).source
|
100
|
+
if key == "map" && value == "true"
|
101
|
+
is_map = true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
self.class.process(self, name, attr_name, is_map)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
YARD::Tags::Library.define_tag("Key for inherited_enumerable(_, :map => true)", :key_name)
|
109
|
+
|
110
|
+
class AttrEnumerableHandler < YARD::Handlers::Ruby::AttributeHandler
|
111
|
+
handles method_call(:attr_enumerable)
|
112
|
+
namespace_only
|
113
|
+
|
114
|
+
def process
|
115
|
+
name = statement.parameters.first.jump(:tstring_content, :ident).source
|
116
|
+
|
117
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, name, scope)
|
118
|
+
object.dynamic = true
|
119
|
+
register(object)
|
120
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "#{name}=", scope)
|
121
|
+
object.dynamic = true
|
122
|
+
register(object)
|
123
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "each_#{name}", scope)
|
124
|
+
object.dynamic = true
|
125
|
+
register(object)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class AttrPredicateHandler < YARD::Handlers::Ruby::AttributeHandler
|
130
|
+
handles method_call(:attr_predicate)
|
131
|
+
namespace_only
|
132
|
+
|
133
|
+
def process
|
134
|
+
name = statement.parameters.first.jump(:tstring_content, :ident).source
|
135
|
+
|
136
|
+
rw = false
|
137
|
+
if statement.parameters[1]
|
138
|
+
rw = (statement.parameters[1].jump(:kw).source == "true")
|
139
|
+
end
|
140
|
+
|
141
|
+
if name.to_s =~ /^(.*)\?$/
|
142
|
+
name = $1
|
143
|
+
end
|
144
|
+
wname, pname = "#{name}=", "#{name}?"
|
145
|
+
|
146
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, pname, scope)
|
147
|
+
object.dynamic = true
|
148
|
+
register(object)
|
149
|
+
object.docstring.create_tag("return", "[Boolean]")
|
150
|
+
if rw
|
151
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, wname, scope)
|
152
|
+
object.dynamic = true
|
153
|
+
object.parameters << ["value", nil]
|
154
|
+
object.signature
|
155
|
+
object.docstring.create_tag("param", "[Boolean] value")
|
156
|
+
object.docstring.create_tag("return", "[Boolean]")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 1.6.
|
9
|
+
- 3
|
10
|
+
version: 1.6.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sylvain Joyeux
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: facets
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/utilrb/configsearch/configuration_finder.rb
|
137
137
|
- lib/utilrb/dir.rb
|
138
138
|
- lib/utilrb/dir/empty.rb
|
139
|
+
- lib/utilrb/doc/rake.rb
|
139
140
|
- lib/utilrb/enumerable.rb
|
140
141
|
- lib/utilrb/enumerable/null.rb
|
141
142
|
- lib/utilrb/enumerable/random_element.rb
|
@@ -147,6 +148,8 @@ files:
|
|
147
148
|
- lib/utilrb/gc.rb
|
148
149
|
- lib/utilrb/gc/force.rb
|
149
150
|
- lib/utilrb/hash.rb
|
151
|
+
- lib/utilrb/hash/map_key.rb
|
152
|
+
- lib/utilrb/hash/map_value.rb
|
150
153
|
- lib/utilrb/hash/recursive_merge.rb
|
151
154
|
- lib/utilrb/hash/slice.rb
|
152
155
|
- lib/utilrb/hash/to_s.rb
|
@@ -162,7 +165,10 @@ files:
|
|
162
165
|
- lib/utilrb/logger.rb
|
163
166
|
- lib/utilrb/logger/forward.rb
|
164
167
|
- lib/utilrb/logger/hierarchy.rb
|
168
|
+
- lib/utilrb/logger/indent.rb
|
165
169
|
- lib/utilrb/logger/io.rb
|
170
|
+
- lib/utilrb/logger/log_pp.rb
|
171
|
+
- lib/utilrb/logger/root.rb
|
166
172
|
- lib/utilrb/marshal/load_with_missing_constants.rb
|
167
173
|
- lib/utilrb/module.rb
|
168
174
|
- lib/utilrb/module/ancestor_p.rb
|
@@ -172,6 +178,7 @@ files:
|
|
172
178
|
- lib/utilrb/module/const_defined_here_p.rb
|
173
179
|
- lib/utilrb/module/define_method.rb
|
174
180
|
- lib/utilrb/module/define_or_reuse.rb
|
181
|
+
- lib/utilrb/module/dsl_attribute.rb
|
175
182
|
- lib/utilrb/module/include.rb
|
176
183
|
- lib/utilrb/module/inherited_enumerable.rb
|
177
184
|
- lib/utilrb/object.rb
|
@@ -181,17 +188,21 @@ files:
|
|
181
188
|
- lib/utilrb/object/singleton_class.rb
|
182
189
|
- lib/utilrb/objectstats.rb
|
183
190
|
- lib/utilrb/pkgconfig.rb
|
191
|
+
- lib/utilrb/rake_common.rb
|
184
192
|
- lib/utilrb/set.rb
|
185
193
|
- lib/utilrb/set/to_s.rb
|
186
194
|
- lib/utilrb/socket/tcp_server.rb
|
187
195
|
- lib/utilrb/socket/tcp_socket.rb
|
196
|
+
- lib/utilrb/spawn.rb
|
188
197
|
- lib/utilrb/symbol/to_str.rb
|
189
198
|
- lib/utilrb/time.rb
|
190
199
|
- lib/utilrb/time/to_hms.rb
|
200
|
+
- lib/utilrb/timepoints.rb
|
191
201
|
- lib/utilrb/unbound_method.rb
|
192
202
|
- lib/utilrb/unbound_method/call.rb
|
193
203
|
- lib/utilrb/value_set.rb
|
194
204
|
- lib/utilrb/weakref.rb
|
205
|
+
- lib/utilrb/yard.rb
|
195
206
|
- patches/gc_live_objects.patch
|
196
207
|
- test/data/test_pkgconfig.pc
|
197
208
|
- test/data/test_pkgconfig_empty.pc
|
@@ -203,6 +214,7 @@ files:
|
|
203
214
|
- test/test_gc.rb
|
204
215
|
- test/test_hash.rb
|
205
216
|
- test/test_kernel.rb
|
217
|
+
- test/test_logger.rb
|
206
218
|
- test/test_misc.rb
|
207
219
|
- test/test_module.rb
|
208
220
|
- test/test_object.rb
|
@@ -213,7 +225,6 @@ files:
|
|
213
225
|
- test/test_time.rb
|
214
226
|
- test/test_unbound_method.rb
|
215
227
|
- test/test_weakref.rb
|
216
|
-
- test/test_logger.rb
|
217
228
|
homepage: http://utilrb.rubyforge.org
|
218
229
|
licenses: []
|
219
230
|
|
@@ -249,22 +260,22 @@ signing_key:
|
|
249
260
|
specification_version: 3
|
250
261
|
summary: Yet another Ruby toolkit
|
251
262
|
test_files:
|
252
|
-
- test/
|
263
|
+
- test/test_time.rb
|
264
|
+
- test/test_weakref.rb
|
265
|
+
- test/test_config.rb
|
253
266
|
- test/test_array.rb
|
254
|
-
- test/test_gc.rb
|
255
|
-
- test/test_module.rb
|
256
267
|
- test/test_kernel.rb
|
268
|
+
- test/test_module.rb
|
257
269
|
- test/test_proc.rb
|
258
|
-
- test/test_weakref.rb
|
259
|
-
- test/test_exception.rb
|
260
|
-
- test/test_unbound_method.rb
|
261
|
-
- test/test_hash.rb
|
262
|
-
- test/test_config.rb
|
263
|
-
- test/test_logger.rb
|
264
270
|
- test/test_set.rb
|
265
|
-
- test/
|
271
|
+
- test/test_hash.rb
|
272
|
+
- test/test_pkgconfig.rb
|
266
273
|
- test/test_objectstats.rb
|
274
|
+
- test/test_unbound_method.rb
|
275
|
+
- test/test_gc.rb
|
276
|
+
- test/test_dir.rb
|
277
|
+
- test/test_misc.rb
|
267
278
|
- test/test_enumerable.rb
|
268
|
-
- test/
|
279
|
+
- test/test_exception.rb
|
280
|
+
- test/test_logger.rb
|
269
281
|
- test/test_object.rb
|
270
|
-
- test/test_time.rb
|