Module: Folder::MagicList
- Defined in:
- lib/require-dsl.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#rel_path ⇒ Object
Returns the value of attribute rel_path.
Instance Method Summary collapse
- #delete_these(objs) ⇒ Object
- #do_require ⇒ Object
- #except(*reg_exps) ⇒ Object
- #fix(str) ⇒ Object
- #matching(*reg_exps) ⇒ Object
- #postfix_rb(str) ⇒ Object
- #show_require(*options) ⇒ Object
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
29 30 31 |
# File 'lib/require-dsl.rb', line 29 def base_path @base_path end |
#rel_path ⇒ Object
Returns the value of attribute rel_path.
30 31 32 |
# File 'lib/require-dsl.rb', line 30 def rel_path @rel_path end |
Instance Method Details
#delete_these(objs) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/require-dsl.rb', line 51 def delete_these(objs) reject! do |obj| a = false objs.each do |del| a = true if obj.include? del end a end end |
#do_require ⇒ Object
32 33 34 35 36 37 |
# File 'lib/require-dsl.rb', line 32 def do_require each do |file| require file end self end |
#except(*reg_exps) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/require-dsl.rb', line 61 def except(*reg_exps) duplicate = self.dup.extend(MagicList) duplicate.each do |file| reg_exps.each {|re| duplicate.delete(file) if file.match(re) } end duplicate end |
#fix(str) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/require-dsl.rb', line 73 def fix(str) postfix_rb(str) str = Regexp.escape(str) str.gsub! '\*', '[a-zA-Z0-9\s_-]*' str.gsub! '/', '\/' str end |
#matching(*reg_exps) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/require-dsl.rb', line 81 def matching(*reg_exps) duplicate = self.dup.extend(MagicList) keep_list = [] duplicate.each do |file| reg_exps.each do |re| re = fix(re) if re.kind_of? String keep_list << file if file.match(re) end end reject_list = (duplicate - keep_list).flatten duplicate.delete_these(reject_list) duplicate end |
#postfix_rb(str) ⇒ Object
69 70 71 |
# File 'lib/require-dsl.rb', line 69 def postfix_rb(str) str << '.rb' if !str.include? '.rb' end |
#show_require(*options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/require-dsl.rb', line 39 def show_require(*) each do |f| if .include? :relative file_path = File.join(rel_path, f) path = Require::Dir.relative_path(base_path, file_path) end path = File.join(base_path, f) if !.include? :relative path end end |