Class: Pact::Provider::ProviderState

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/provider/provider_state.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, namespace, &block) ⇒ ProviderState

Returns a new instance of ProviderState.



46
47
48
49
50
51
52
53
54
# File 'lib/pact/provider/provider_state.rb', line 46

def initialize name, namespace, &block
  @name = name
  @namespace = namespace
  @set_up_defined = false
  @tear_down_defined = false
  @no_op_defined = false
  instance_eval(&block)
  validate
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/pact/provider/provider_state.rb', line 18

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



19
20
21
# File 'lib/pact/provider/provider_state.rb', line 19

def namespace
  @namespace
end

Class Method Details

.current_namespacesObject



33
34
35
# File 'lib/pact/provider/provider_state.rb', line 33

def self.current_namespaces
  @@current_namespaces ||= []
end

.get(name, options = {}) ⇒ Object



37
38
39
40
# File 'lib/pact/provider/provider_state.rb', line 37

def self.get name, options = {}
  fullname = options[:for] ? "#{options[:for]}.#{name}" : name
  (provider_states[fullname] || provider_states[fullname.to_sym]) || provider_states[name]
end

.provider_state(name, &block) ⇒ Object



21
22
23
# File 'lib/pact/provider/provider_state.rb', line 21

def self.provider_state name, &block
  ProviderState.new(name, current_namespaces.join('.'), &block)
end

.provider_statesObject



29
30
31
# File 'lib/pact/provider/provider_state.rb', line 29

def self.provider_states
  @@provider_states ||= {}
end

.register(name, provider_state) ⇒ Object



25
26
27
# File 'lib/pact/provider/provider_state.rb', line 25

def self.register name, provider_state
  provider_states[name] = provider_state
end

Instance Method Details

#no_opObject



74
75
76
# File 'lib/pact/provider/provider_state.rb', line 74

def no_op
  @no_op_defined = true
end

#registerObject



42
43
44
# File 'lib/pact/provider/provider_state.rb', line 42

def register
  self.class.register(namespaced(name), self)
end

#set_up(&block) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/pact/provider/provider_state.rb', line 56

def set_up &block
  if block_given?
    @set_up_block = block
    @set_up_defined = true
  elsif @set_up_block
    instance_eval &@set_up_block
  end
end

#tear_down(&block) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/pact/provider/provider_state.rb', line 65

def tear_down &block
  if block_given?
    @tear_down_block = block
    @tear_down_defined = true
  elsif @tear_down_block
    instance_eval &@tear_down_block
  end
end