Class: SimpleShipping::Abstract::Builder
- Inherits:
-
Object
- Object
- SimpleShipping::Abstract::Builder
- 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.
Direct Known Subclasses
Fedex::PackageBuilder, Fedex::PartyBuilder, Fedex::ShipmentBuilder, Ups::PackageBuilder, Ups::PartyBuilder, Ups::ShipmentBuilder
Class Method Summary collapse
-
.build(model, opts = {}) ⇒ Object
Parameters: model - kind of Model opts - hash of options.
-
.set_default_opts(opts = {}) ⇒ Object
Allows to set default option values is subclasses.
Instance Method Summary collapse
-
#build ⇒ Object
Should be implemented by subclasses.
-
#validate ⇒ Object
Should be implemented by subclass if subclass needs to do some validation.
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.
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
#build ⇒ Object
Should be implemented by subclasses. But by default returns empty hash.
27 |
# File 'lib/simple_shipping/abstract/builder.rb', line 27 def build; {}; end |
#validate ⇒ Object
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 |