Class: RR::DoubleDefinitions::DoubleDefinitionCreator

Inherits:
Object
  • Object
show all
Includes:
StrategyExecutionMethods, StrategySetupMethods, Space::Reader
Defined in:
lib/rr/double_definitions/double_definition_creator.rb

Overview

:nodoc

Direct Known Subclasses

ChildDoubleDefinitionCreator

Defined Under Namespace

Modules: StrategyExecutionMethods, StrategySetupMethods Classes: DoubleDefinitionCreatorError

Constant Summary collapse

NO_SUBJECT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StrategyExecutionMethods

#create

Methods included from StrategySetupMethods

#no_subject?

Methods included from Space::Reader

#space

Constructor Details

#initializeDoubleDefinitionCreator

Returns a new instance of DoubleDefinitionCreator.



64
65
66
67
68
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 64

def initialize
  @verification_strategy = nil
  @implementation_strategy = Strategies::Implementation::Reimplementation.new(self)
  @scope_strategy = Strategies::Scope::Instance.new(self)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def definition
  @definition
end

#handlerObject (readonly)

Returns the value of attribute handler.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def handler
  @handler
end

#implementation_strategyObject (readonly)

Returns the value of attribute implementation_strategy.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def implementation_strategy
  @implementation_strategy
end

#scope_strategyObject (readonly)

Returns the value of attribute scope_strategy.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def scope_strategy
  @scope_strategy
end

#subjectObject (readonly)

Returns the value of attribute subject.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def subject
  @subject
end

#verification_strategyObject (readonly)

Returns the value of attribute verification_strategy.



54
55
56
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 54

def verification_strategy
  @verification_strategy
end

Class Method Details

.register_implementation_strategy_class(strategy_class, method_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 21

def register_implementation_strategy_class(strategy_class, method_name)
  class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
  def #{method_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
    add_strategy(subject, method_name, definition_eval_block) do
      self.implementation_strategy = #{strategy_class.name}.new(self)
    end
  end
  CLASS

  class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
  def #{method_name}!(method_name=nil, &definition_eval_block)
    #{method_name}(Object.new, method_name, &definition_eval_block)
  end
  CLASS
end

.register_scope_strategy_class(strategy_class, method_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 37

def register_scope_strategy_class(strategy_class, method_name)
  class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
  def #{method_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
    add_strategy(subject, method_name, definition_eval_block) do
      self.scope_strategy = #{strategy_class.name}.new(self)
    end
  end
  CLASS

  class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
  def #{method_name}!(method_name=nil, &definition_eval_block)
    #{method_name}(Object.new, method_name, &definition_eval_block)
  end
  CLASS
end

.register_verification_strategy_class(strategy_class, method_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 5

def register_verification_strategy_class(strategy_class, method_name)
  class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
  def #{method_name}(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
    add_strategy(subject, method_name, definition_eval_block) do
      self.verification_strategy = #{strategy_class.name}.new(self)
    end
  end
  CLASS

  class_eval((<<-CLASS), __FILE__, __LINE__ + 1)
  def #{method_name}!(method_name=nil, &definition_eval_block)
    #{method_name}(Object.new, method_name, &definition_eval_block)
  end
  CLASS
end

Instance Method Details

#method_nameObject



74
75
76
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 74

def method_name
  @verification_strategy.method_name
end

#root_subjectObject



70
71
72
# File 'lib/rr/double_definitions/double_definition_creator.rb', line 70

def root_subject
  subject
end