Class: LazyDir
- Inherits:
-
Array
- Object
- Array
- LazyDir
- Defined in:
- lib/safegem/lazy_dir.rb
Constant Summary collapse
- OrigDir =
Dir
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(method, args, block = nil) ⇒ LazyDir
constructor
A new instance of LazyDir.
-
#to_a ⇒ Object
(also: #to_ary)
this method is meant to be called lazily after the $SAFE has reverted to 0.
- #to_yaml(opts = {}) ⇒ Object
Constructor Details
#initialize(method, args, block = nil) ⇒ LazyDir
Returns a new instance of LazyDir.
4 5 6 |
# File 'lib/safegem/lazy_dir.rb', line 4 def initialize(method, args, block = nil) @method, @args, @block = method, args, block end |
Class Method Details
.method_missing(m, *a, &b) ⇒ Object
33 34 35 |
# File 'lib/safegem/lazy_dir.rb', line 33 def method_missing m, *a, &b OrigDir.send m, *a, &b end |
Instance Method Details
#to_a ⇒ Object Also known as: to_ary
this method is meant to be called lazily after the $SAFE has reverted to 0
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/safegem/lazy_dir.rb', line 9 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.('.') + File::SEPARATOR files.reject do |f| File.(f) !~ %r{^#{cur_dir}} end end |
#to_yaml(opts = {}) ⇒ Object
21 22 23 |
# File 'lib/safegem/lazy_dir.rb', line 21 def to_yaml(opts = {}) to_a.to_yaml(opts) end |