Class: Folder::Magic
- Inherits:
-
Object
- Object
- Folder::Magic
- Defined in:
- lib/require-dsl.rb
Instance Attribute Summary collapse
-
#current_path ⇒ Object
Returns the value of attribute current_path.
-
#dir_stack ⇒ Object
Returns the value of attribute dir_stack.
Instance Method Summary collapse
- #all(*globs) ⇒ Object
- #enter(dir) ⇒ Object
- #exit ⇒ Object
-
#initialize ⇒ Magic
constructor
A new instance of Magic.
- #require_all(*folders) ⇒ Object
Constructor Details
#initialize ⇒ Magic
Returns a new instance of Magic.
100 101 102 103 |
# File 'lib/require-dsl.rb', line 100 def initialize @dir_stack = [] @current_path = FileUtils.pwd end |
Instance Attribute Details
#current_path ⇒ Object
Returns the value of attribute current_path.
97 98 99 |
# File 'lib/require-dsl.rb', line 97 def current_path @current_path end |
#dir_stack ⇒ Object
Returns the value of attribute dir_stack.
98 99 100 |
# File 'lib/require-dsl.rb', line 98 def dir_stack @dir_stack end |
Instance Method Details
#all(*globs) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/require-dsl.rb', line 125 def all(*globs) globs = '**/*.rb' if globs.empty? list = FileList.new(globs) list.extend(MagicList) list.base_path = dir_stack.first list.rel_path = current_path list.freeze end |
#enter(dir) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/require-dsl.rb', line 105 def enter(dir) path = FileUtils.pwd dir_stack.push path FileUtils.cd dir if !dir.empty? @current_path = FileUtils.pwd if block_given? yield self exit end self end |
#exit ⇒ Object
117 118 119 120 121 122 |
# File 'lib/require-dsl.rb', line 117 def exit current_path = dir_stack.last old_dir = dir_stack.last dir_stack.pop FileUtils.cd old_dir if old_dir end |