Class: SimpleShipping::Abstract::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_shipping/abstract/builder.rb

Overview

Kind of an abstract class which should be used to create model builders. Model builder “knows” how to represent its model for a its service. This class provides only common skeleton for subclasses.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(model, opts = {}) ⇒ Object

Parameters:

model - kind of {Abstract::Model}
opts - hash of options. Every builder can have its own specific set of options

Returns:

Hash which can be used by Savon to build a part of SOAP request.

Raises:



13
14
15
16
17
18
19
# File 'lib/simple_shipping/abstract/builder.rb', line 13

def self.build(model, opts = {})
  raise(ValidationError.new(model)) unless model.valid?

  builder = self.new(model, opts)
  builder.validate
  builder.build
end

.set_default_opts(opts = {}) ⇒ Object

Allows to set default option values is subclasses.



22
23
24
# File 'lib/simple_shipping/abstract/builder.rb', line 22

def self.set_default_opts(opts = {})
  self.default_opts = opts
end

Instance Method Details

#buildObject

Should be implemented by subclasses. But by default returns empty hash.



27
# File 'lib/simple_shipping/abstract/builder.rb', line 27

def build; {}; end

#validateObject

Should be implemented by subclass if subclass needs to do some validation.



30
# File 'lib/simple_shipping/abstract/builder.rb', line 30

def validate; end