Class: Autoloaded::Specification Private

Inherits:
Object
  • Object
show all
Defined in:
lib/autoloaded/specification.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Describes regulations for autoloading.

Since:

  • 1.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*elements) ⇒ Specification

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Constructs a new Specification with the specified 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

Parameters:

  • elements

    the value of #elements

See Also:

Since:

  • 1.3



31
32
33
# File 'lib/autoloaded/specification.rb', line 31

def initialize(*elements)
  @elements = elements
end

Instance Attribute Details

#elementsArray (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The elements of the specification.

Returns:

  • (Array)

Since:

  • 1.3



15
16
17
# File 'lib/autoloaded/specification.rb', line 15

def elements
  @elements
end

Instance Method Details

#==(other_object) ⇒ true, false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compares the Specification with the specified other_object.

Parameters:

  • other_object

    another object

Returns:

  • (true)

    if other_object is equal to the Specification

  • (false)

    if other_object is not equal to the Specification

Since:

  • 1.3



41
42
43
44
45
# File 'lib/autoloaded/specification.rb', line 41

def ==(other_object)
  return false unless other_object.kind_of?(self.class)

  other_object.elements == elements
end

#match(source_filename) ⇒ Symbol, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Provides a matching constant from #elements for the specified source_filename.

Parameters:

  • source_filename (String)

    the name of a source file

Returns:

  • (Symbol)

    a matching constant

  • (Array of Symbol)

    matching constants

  • (nil)

    if there is no matching constant

See Also:

Since:

  • 1.3



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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