Class: Folder::Magic

Inherits:
Object
  • Object
show all
Defined in:
lib/require-dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMagic

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_pathObject

Returns the value of attribute current_path.



97
98
99
# File 'lib/require-dsl.rb', line 97

def current_path
  @current_path
end

#dir_stackObject

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

#exitObject



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

#require_all(*folders) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/require-dsl.rb', line 134

def require_all(*folders)
  return all.dup.extend(MagicList).do_require if folders.empty?
  folders.each do |folder|
    enter folder do |f|
      f.all.dup.extend(MagicList).do_require
    end
  end
end