Module: CassandraMapper::Support::Dependencies

Extended by:
Dependencies
Included in:
Dependencies
Defined in:
lib/cassandra_mapper/support/dependencies.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#autoloaded?(desc) ⇒ Boolean

Determine if the given constant has been automatically loaded.

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/cassandra_mapper/support/dependencies.rb', line 15

def autoloaded?(desc)
  # No name => anonymous module.
  return false if desc.is_a?(Module) && desc.anonymous?
  name = to_constant_name desc
  return false unless qualified_const_defined? name
  return autoloaded_constants.include?(name)
end

#local_const_defined?(mod, const) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


49
50
51
# File 'lib/cassandra_mapper/support/dependencies.rb', line 49

def local_const_defined?(mod, const)
  mod.const_defined?(const)
end

#qualified_const_defined?(path) ⇒ Boolean

Is the provided constant path defined?

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/cassandra_mapper/support/dependencies.rb', line 37

def qualified_const_defined?(path)
  names = path.sub(/^::/, '').to_s.split('::')

  names.inject(Object) do |mod, name|
    return false unless local_const_defined?(mod, name)
    mod.const_get name
  end
end

#to_constant_name(desc) ⇒ Object

Convert the provided const desc to a qualified constant name (as a string). A module, class, symbol, or string may be provided.



25
26
27
28
29
30
31
32
33
34
# File 'lib/cassandra_mapper/support/dependencies.rb', line 25

def to_constant_name(desc) #:nodoc:
  name = case desc
    when String then desc.sub(/^::/, '')
    when Symbol then desc.to_s
    when Module
      desc.name.presence ||
        raise(ArgumentError, "Anonymous modules have no name to be referenced by")
    else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}"
  end
end