Class: Naught::NullClassBuilder::Commands::Mimic Private

Inherits:
Naught::NullClassBuilder::Command show all
Defined in:
lib/naught/null_class_builder/commands/mimic.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.

Build a null class that mimics an existing class or instance

Direct Known Subclasses

Impersonate

Instance Attribute Summary collapse

Attributes inherited from Naught::NullClassBuilder::Command

#builder

Instance Method Summary collapse

Constructor Details

#initialize(builder, class_to_mimic_or_options, options = {}) ⇒ Mimic

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.

Create a mimic command for a class or instance

Parameters:

  • builder (NullClassBuilder)
  • class_to_mimic_or_options (Class, Hash)
  • options (Hash) (defaults to: {})


47
48
49
50
51
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 47

def initialize(builder, class_to_mimic_or_options, options = {})
  super(builder)
  parse_arguments(class_to_mimic_or_options, options)
  configure_builder
end

Instance Attribute Details

#class_to_mimicClass (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 class being mimicked by the null object

Returns:

  • (Class)

    class being mimicked



23
24
25
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 23

def class_to_mimic
  @class_to_mimic
end

#example_instanceObject? (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 example instance for dynamic method discovery

Returns:

  • (Object, nil)

    example instance or nil



35
36
37
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 35

def example_instance
  @example_instance
end

#include_dynamicBoolean (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.

Whether to include dynamically-defined methods

Returns:

  • (Boolean)

    whether to include dynamic methods



39
40
41
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 39

def include_dynamic
  @include_dynamic
end

#include_superBoolean (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.

Whether to include superclass methods when mimicking

Returns:

  • (Boolean)

    whether to include superclass methods



27
28
29
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 27

def include_super
  @include_super
end

#singleton_classClass (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 singleton class being mimicked (for instance-based mimicking)

Returns:

  • (Class)

    singleton class being mimicked



31
32
33
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 31

def singleton_class
  @singleton_class
end

Instance Method Details

#callvoid

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.

This method returns an undefined value.

Install stubbed methods from the target class or instance



57
58
59
# File 'lib/naught/null_class_builder/commands/mimic.rb', line 57

def call
  defer { |subject| methods_to_stub.each { |name| builder.stub_method(subject, name) } }
end