Class: AWS::Core::XML::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/core/xml/stub.rb

Overview

This class takes the rules from an XML parser and then returns a stubbed reponse. This response has placeholder values based on the grammar, e.g.

  • Lists are stubbed with empty arrays

  • Indexes become empty hashes

  • Numeric types are returned as 0

  • etc

This is used primarily to help with the AWS.stub! utility.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ Stub

Returns a new instance of Stub.

Parameters:

  • rules (Hash)


32
33
34
# File 'lib/aws/core/xml/stub.rb', line 32

def initialize rules
  @rules = rules
end

Instance Attribute Details

#rulesHash (readonly)

Returns:

  • (Hash)


37
38
39
# File 'lib/aws/core/xml/stub.rb', line 37

def rules
  @rules
end

Class Method Details

.simulate(rules) ⇒ Hash

Returns a hash with stubbed values as if it had parsed an empty xml document.

Parameters:

  • rules (Hash)

    An XML::Parser rule set.

Returns:

  • (Hash)


56
57
58
59
# File 'lib/aws/core/xml/stub.rb', line 56

def self.simulate rules
  stub = Stub.new(rules)
  stub.simulate
end

Instance Method Details

#simulateHash

Returns a hash with stubbed values as if it had parsed an empty xml document.

Returns:

  • (Hash)


42
43
44
45
46
47
48
49
50
# File 'lib/aws/core/xml/stub.rb', line 42

def simulate 
  if rules[:children]
    data = stub_data_for(rules)
    apply_empty_indexes(rules, data)
    data
  else
    {}
  end
end