Module: Finder::Find::Base

Included in:
Gem, Roll, Site
Defined in:
lib/finder/base.rb

Overview

Base module provides helper methods to other finders.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

When included into a module, that module is atuomatically self extended.



13
14
15
# File 'lib/finder/base.rb', line 13

def self.included(mod)
  mod.extend(mod)
end

Instance Method Details

#append_extensions(match, options = {}) ⇒ Object (private)

Append requirable extensions to match glob.



59
60
61
62
63
64
# File 'lib/finder/base.rb', line 59

def append_extensions(match, options={})
  unless Find::EXTENSIONS.include?(File.extname(match))
    match = match + '{' + Find::EXTENSIONS.join(',') + '}'
  end
  match
end

#feature(match, options = {}) ⇒ Object

Like #load_path but searches only for requirable feature files and returns relative paths by default.



32
33
34
35
36
# File 'lib/finder/base.rb', line 32

def feature(match, options={})
  options[:relative] = true unless options.key?(:relative) or options.key?(:absolute)
  match = append_extensions(match, options)
  load_path(match, options)
end

#valid_load_options(options) ⇒ Object (private)

Validate and normalize load options.

Parameters:

  • options (Hash)


45
46
47
48
49
50
51
52
53
# File 'lib/finder/base.rb', line 45

def valid_load_options(options)
  if options.key?(:relative) && options.key?(:absolute)
    raise ArgumentError, "must be either relative or absolute" unless options[:relative] ^ options[:absolute]
  end

  options[:relative] = false if options[:absolute]

  options
end