Module: Autoloaded

Defined in:
lib/autoloaded.rb,
lib/autoloaded/version.rb,
lib/autoloaded/autoloader.rb,
lib/autoloaded/specification.rb

Defined Under Namespace

Modules: Deprecation, Inflection, Warning Classes: Autoloader, LoadPathedDirectory, Specification, Specifications

Constant Summary collapse

VERSION =

The current version of the Autoloaded project.

Since:

  • 0.0.1

'2.2.1'

Class Method Summary collapse

Class Method Details

.module {|Autoloader| ... } ⇒ Array of Array Also known as: class

Autoloads constants that match files in the source directory.

Examples:

Autoloading a namespace

# lib/my_awesome_gem/db.rb

module MyAwesomeGem

  Autoloaded.module { }

end

Autoloading with optional specifications

# lib/my_awesome_gem/db.rb

module MyAwesomeGem

  class DB

    results = Autoloaded.class do |autoloaded|
      autoloaded.with   :MySQL, :PostgreSQL, [:Access, :SQLServer] => 'MicroSoft'
      autoloaded.except 'SELF-DESTRUCT!'
    end
    STDOUT.puts results.inspect  # See output below.

  end

end

# [[:Access,     'my_awesome_gem/db/MicroSoft'  ],
#  [:SQLServer,  'my_awesome_gem/db/MicroSoft'  ],
#  [:MySQL,      'my_awesome_gem/db/mysql'      ],
#  [:Oracle,     'my_awesome_gem/db/oracle'     ],
#  [:PostgreSQL, 'my_awesome_gem/db/postgre_sql']]

Yields:

  • (Autoloader)

    accepts options for regulating autoloading

Returns:

  • (Array of Array)

    the arguments passed to each autoload statement made

Raises:

  • (LocalJumpError)

    no block is given

Since:

  • 1.3


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/autoloaded.rb', line 58

module(&block)
    raise(::LocalJumpError, 'no block given (yield)') unless block

    yield(autoloader = Autoloader.new(block.binding))
    autoloader.autoload!
  end

  # Enables or disables warning messages depending on the specified _enabling_
  # argument.
  #
  # @param [Object] enabling disables warnings if +nil+ or +false+
  #
  # @yield if a block is given, the value of _#warn?_ is reset after the block is
  #        called
  #
  # @return if a block is given, the result of calling the block
  # @return [Autoloaded] if a block is not given, _Autoloaded_ (_Module_)
  #
  # @since 1.3
  #
  # @see .warn?
  def self.warn(enabling, &block)
    result = Warning.enable(enabling, &block)

    block ? result : self
  end

  # Indicates whether warning messages are enabled or disabled.
  #
  # @return [true] if warning messages are enabled
  # @return [false] if warning messages are disabled
  #
  # @since 1.3
  #
  # @see .warn
  def self.warn?
    Warning.enabled?
  end

  class << self

    alias_method :class, :module

  end

end

.warn(enabling) { ... } ⇒ Object

Enables or disables warning messages depending on the specified enabling argument.

Parameters:

  • enabling (Object)

    disables warnings if nil or false

Yields:

  • if a block is given, the value of #warn? is reset after the block is called

Returns:

  • if a block is given, the result of calling the block

  • (Autoloaded)

    if a block is not given, Autoloaded (Module)

See Also:

Since:

  • 1.3


79
80
81
82
83
# File 'lib/autoloaded.rb', line 79

def self.warn(enabling, &block)
  result = Warning.enable(enabling, &block)

  block ? result : self
end

.warn?true, false

Indicates whether warning messages are enabled or disabled.

Returns:

  • (true)

    if warning messages are enabled

  • (false)

    if warning messages are disabled

See Also:

Since:

  • 1.3


93
94
95
# File 'lib/autoloaded.rb', line 93

def self.warn?
  Warning.enabled?
end