123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Mocks::ObjectReference Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-mocks/lib/rspec/mocks/object_reference.rb

Constant Summary

Class Method Summary

Class Method Details

.anonymous_module?(mod) ⇒ Boolean (private)

1.8.7

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 35

def self.anonymous_module?(mod)
  !name_of(mod)
end

.for(object_module_or_name, allow_direct_object_refs = false)

Returns an appropriate Object or Module reference based on the given argument.

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 7

def self.for(object_module_or_name, allow_direct_object_refs=false)
  case object_module_or_name
  when Module
    if anonymous_module?(object_module_or_name)
      DirectObjectReference.new(object_module_or_name)
    else
      # Use a `NamedObjectReference` if it has a name because this
      # will use the original value of the constant in case it has
      # been stubbed.
      NamedObjectReference.new(name_of(object_module_or_name))
    end
  when String
    NamedObjectReference.new(object_module_or_name)
  else
    if allow_direct_object_refs
      DirectObjectReference.new(object_module_or_name)
    else
      raise ArgumentError,
            "Module or String expected, got #{object_module_or_name.inspect}"
    end
  end
end

.name_of(mod) (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 41

def self.name_of(mod)
  MODULE_NAME_METHOD.bind(mod).call
end