Module: SearchablePaths::ClassMethods
- Defined in:
- lib/mixins/searchable_paths.rb
Instance Method Summary collapse
-
#default_paths ⇒ Object
These are the default search paths in order:.
-
#has_searchable_paths(opts = {}) ⇒ Object
Specify that a particular class has methods for searchable paths.
-
#searchable_paths ⇒ Object
returns the full set of valid searchable paths, given the options.
- #searchable_paths_dir ⇒ Object
- #searchable_paths_dirs ⇒ Object
Instance Method Details
#default_paths ⇒ Object
These are the default search paths in order:
-
current working directory (Dir.pwd)
44 45 46 47 48 |
# File 'lib/mixins/searchable_paths.rb', line 44 def default_paths [ Dir.pwd ] end |
#has_searchable_paths(opts = {}) ⇒ Object
Specify that a particular class has methods for searchable paths.
Options:
-
:dirs
: array of directories to look in under the search paths. (default:["/"]
) -
:dir
: set the directory to look in under the search paths. Use either dir or dirs, not both. (default:/
) -
:paths
: overwrite all default paths and set the paths to this array exactly -
:append_paths
: append these paths to any existing paths -
:prepend_paths
: prepend these paths to any existing paths
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mixins/searchable_paths.rb', line 24 def has_searchable_paths(opts={}) class_eval do @searchable_paths_dirs = [opts[:dir]] if opts[:dir] @searchable_paths_dirs = opts[:dirs] if opts[:dirs] @paths_override = opts[:paths] if opts[:paths] @paths_prepend = opts[:prepend_paths] || [] @paths_append = opts[:append_paths] || [] end extend SearchablePaths::SingletonMethods include SearchablePaths::InstanceMethods end |
#searchable_paths ⇒ Object
returns the full set of valid searchable paths, given the options
51 52 53 54 |
# File 'lib/mixins/searchable_paths.rb', line 51 def searchable_paths return @paths_override if @paths_override && @paths_override.size > 0 @searchable_paths ||= @paths_prepend + default_paths + @paths_append end |
#searchable_paths_dir ⇒ Object
36 |
# File 'lib/mixins/searchable_paths.rb', line 36 def searchable_paths_dir; @searchable_paths_dirs.first; end |
#searchable_paths_dirs ⇒ Object
37 38 39 |
# File 'lib/mixins/searchable_paths.rb', line 37 def searchable_paths_dirs @searchable_paths_dirs && @searchable_paths_dirs.size > 0 ? @searchable_paths_dirs : ["/"] end |