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.
15 16 17 |
# File 'lib/require-dsl.rb', line 15 def base_path @base_path end |
#rel_path ⇒ Object
Returns the value of attribute rel_path.
16 17 18 |
# File 'lib/require-dsl.rb', line 16 def rel_path @rel_path end |
Instance Method Details
#delete_these(objs) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/require-dsl.rb', line 37 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
18 19 20 21 22 23 |
# File 'lib/require-dsl.rb', line 18 def do_require each do |file| require file end self end |
#except(*reg_exps) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/require-dsl.rb', line 47 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
59 60 61 62 63 64 65 |
# File 'lib/require-dsl.rb', line 59 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
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/require-dsl.rb', line 67 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
55 56 57 |
# File 'lib/require-dsl.rb', line 55 def postfix_rb(str) str << '.rb' if !str.include? '.rb' end |
#show_require(*options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/require-dsl.rb', line 25 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 |