Sha256: 8d0b0a08283c2783f9375e07d1c20a887b7e53899a53825e023df0a0a448ca8f
Contents?: true
Size: 939 Bytes
Versions: 12
Compression:
Stored size: 939 Bytes
Contents
class LazyDir < Array OrigDir = Dir def initialize(method, args, block = nil) @method, @args, @block = method, args, block end # this method is meant to be called lazily after the $SAFE has reverted to 0 def to_a raise SecurityError unless %w([] glob).include? @method files = OrigDir.send(@method, *@args, &@block) # only return files within the current directory cur_dir = File.expand_path('.') + File::SEPARATOR files.reject do |f| File.expand_path(f) !~ %r{^#{cur_dir}} end end alias_method :to_ary, :to_a def to_yaml(opts = {}) to_a.to_yaml(opts) end class << self # these methods are meant to be called with tainted data in a $SAFE >= 3 %w(glob []).each do |method_name| define_method method_name do |*a| LazyDir.new method_name, a end end def method_missing m, *a, &b OrigDir.send m, *a, &b end end end LazyDir.freeze
Version data entries
12 entries across 12 versions & 1 rubygems