Class: Opal::PathReader
- Inherits:
-
Object
- Object
- Opal::PathReader
- Defined in:
- opal/lib/opal/path_reader.rb
Constant Summary
- RELATIVE_PATH_REGEXP =
%r{#{Opal::REGEXP_START}\.?\.#{Regexp.quote File::SEPARATOR}}
- DEFAULT_EXTENSIONS =
['.js', '.js.rb', '.rb', '.opalerb']
Instance Method Summary collapse
- #append_paths(*paths) ⇒ Object
- #expand(path) ⇒ Object
- #extensions ⇒ Object
-
#initialize(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS) ⇒ PathReader
constructor
A new instance of PathReader.
- #paths ⇒ Object
- #read(path) ⇒ Object
Constructor Details
#initialize(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS) ⇒ PathReader
Returns a new instance of PathReader
10 11 12 13 14 |
# File 'opal/lib/opal/path_reader.rb', line 10 def initialize(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS) @file_finder = Hike::Trail.new @file_finder.append_paths(*paths) @file_finder.append_extensions(*extensions) end |
Instance Method Details
#append_paths(*paths) ⇒ Object
38 39 40 |
# File 'opal/lib/opal/path_reader.rb', line 38 def append_paths(*paths) file_finder.append_paths(*paths) end |
#expand(path) ⇒ Object
22 23 24 25 26 27 28 |
# File 'opal/lib/opal/path_reader.rb', line 22 def (path) if Pathname.new(path).absolute? || path =~ RELATIVE_PATH_REGEXP path else find_path(path) end end |
#extensions ⇒ Object
34 35 36 |
# File 'opal/lib/opal/path_reader.rb', line 34 def extensions file_finder.extensions end |
#paths ⇒ Object
30 31 32 |
# File 'opal/lib/opal/path_reader.rb', line 30 def paths file_finder.paths end |
#read(path) ⇒ Object
16 17 18 19 20 |
# File 'opal/lib/opal/path_reader.rb', line 16 def read(path) full_path = (path) return nil if full_path.nil? File.open(full_path, 'rb:UTF-8'){|f| f.read} end |