class Autoloaded::Specification
Describes regulations for autoloading.
@since 1.3
@api private
Attributes
The elements of the specification.
@return [Array]
Public Class Methods
Constructs a new Specification with the specified elements.
@param elements the value of #elements
Valid arguments include:
-
Symbol values
-
Array values comprising Symbol values
-
Hash values comprising Symbol, String, and/or Array values described above, which will autoload specified constants from their associated source files
-
Any combination of the options described above
@see elements
# File lib/autoloaded/specification.rb, line 31 def initialize(*elements) @elements = elements end
Public Instance Methods
Compares the Specification with the specified other_object.
@param other_object another object
@return [true] if other_object is equal to the Specification @return [false] if other_object is not equal to the Specification
# File lib/autoloaded/specification.rb, line 41 def ==(other_object) return false unless other_object.kind_of?(self.class) other_object.elements == elements end
Provides a matching constant from #elements for the specified source_filename.
@param [String] source_filename the name of a source file
@return [Symbol] a matching constant @return [Array of Symbol] matching constants @return [nil] if there is no matching constant
@see elements
# File lib/autoloaded/specification.rb, line 57 def match(source_filename) matched = elements.detect do |element| if element.kind_of?(::Hash) element.each do |key, value| return value if source_filename_match?(source_filename, key) return key if source_filename_match?(source_filename, value) end false else source_filename_match? source_filename, element end end matched.kind_of?(::String) ? Inflection.to_constant_name(matched) : matched end
Private Instance Methods
# File lib/autoloaded/specification.rb, line 76 def source_filename_match?(file, array_or_file_or_constant) case array_or_file_or_constant when ::Array array_or_file_or_constant.detect do |o| source_filename_match? file, o end when ::Symbol source_filename_match_constant_name? file, array_or_file_or_constant else source_filename_match_filename? file, array_or_file_or_constant end end
# File lib/autoloaded/specification.rb, line 89 def source_filename_match_constant_name?(file, constant) Inflection.to_constant_name(file).to_s.casecmp(constant.to_s).zero? end
# File lib/autoloaded/specification.rb, line 93 def source_filename_match_filename?(file1, file2) file1.to_s.casecmp(file2.to_s).zero? end