Class: Rum::Path
- Inherits:
-
Object
- Object
- Rum::Path
- Defined in:
- lib/rum/barrel.rb
Class Method Summary collapse
- .contents(dir) ⇒ Object
- .normalize(path) ⇒ Object
- .run(path) ⇒ Object
- .sanitize(path) ⇒ Object
- .select(dir) ⇒ Object
- .select_and_run(dir) ⇒ Object
Class Method Details
.contents(dir) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rum/barrel.rb', line 5 def self.contents dir paths = [] dir = File.join(dir, '') dir_dots = /(?:^|\/)\.\.?$/ # /.. or /. Dir.glob(dir + '**/*', File::FNM_DOTMATCH).each do |path| sub_path = path[(dir.length)..-1].encode(Encoding::UTF_8, \ Encoding::ISO_8859_1) paths << sub_path unless sub_path =~ dir_dots end paths end |
.normalize(path) ⇒ Object
39 40 41 |
# File 'lib/rum/barrel.rb', line 39 def self.normalize path path.gsub('\\', '/') end |
.run(path) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rum/barrel.rb', line 22 def self.run path if File.extname(path) == '.rb' eval(IO.read(path)) else start path end end |
.sanitize(path) ⇒ Object
35 36 37 |
# File 'lib/rum/barrel.rb', line 35 def self.sanitize path path.gsub(/[\/\\|?*><":]/, '-') end |
.select(dir) ⇒ Object
17 18 19 20 |
# File 'lib/rum/barrel.rb', line 17 def self.select dir path = Gui.choose(nil, contents(dir)) (File.join(dir, path)) if path end |
.select_and_run(dir) ⇒ Object
30 31 32 33 |
# File 'lib/rum/barrel.rb', line 30 def self.select_and_run dir path = select(dir) run path if path end |