diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
commit | be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /web/server/h2o/libh2o/deps/mruby/lib/mruby-core-ext.rb | |
parent | Initial commit. (diff) | |
download | netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip |
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | web/server/h2o/libh2o/deps/mruby/lib/mruby-core-ext.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/deps/mruby/lib/mruby-core-ext.rb b/web/server/h2o/libh2o/deps/mruby/lib/mruby-core-ext.rb new file mode 100644 index 00000000..4c6d3ca7 --- /dev/null +++ b/web/server/h2o/libh2o/deps/mruby/lib/mruby-core-ext.rb @@ -0,0 +1,79 @@ +class Object + class << self + def attr_block(*syms) + syms.flatten.each do |sym| + class_eval "def #{sym}(&block);block.call(@#{sym}) if block_given?;@#{sym};end" + end + end + end +end + +class String + def relative_path_from(dir) + Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s + end + + def relative_path + relative_path_from(Dir.pwd) + end + + # Compatible with 1.9 on 1.8 + def %(params) + if params.is_a?(Hash) + str = self.clone + params.each do |k, v| + str.gsub!("%{#{k}}") { v } + end + str + else + if params.is_a?(Array) + sprintf(self, *params) + else + sprintf(self, params) + end + end + end +end + +class Symbol + # Compatible with 1.9 on 1.8 + def to_proc + proc { |obj, *args| obj.send(self, *args) } + end +end + +module Enumerable + # Compatible with 1.9 on 1.8 + def each_with_object(memo) + return to_enum :each_with_object, memo unless block_given? + each { |obj| yield obj, memo } + memo + end +end + +$pp_show = true + +if $verbose.nil? + if Rake.respond_to?(:verbose) && !Rake.verbose.nil? + if Rake.verbose.class == TrueClass + # verbose message logging + $pp_show = false + else + $pp_show = true + Rake.verbose(false) + end + else + # could not identify rake version + $pp_show = false + end +else + $pp_show = false if $verbose +end + +def _pp(cmd, src, tgt=nil, options={}) + return unless $pp_show + + width = 5 + template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s" + puts template % [cmd, src, tgt ? "-> #{tgt}" : nil] +end |