Class: Usps::Imis::Mocks::BusinessObject
- Inherits:
-
Object
- Object
- Usps::Imis::Mocks::BusinessObject
- Defined in:
- lib/usps/imis/mocks/business_object.rb
Overview
Mock data response for testing
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #delete ⇒ Object (also: #destroy)
- #get ⇒ Object (also: #read)
- #get_field(name) ⇒ Object (also: #fetch, #[])
- #get_fields(*field_names) ⇒ Object (also: #fetch_all)
-
#initialize(**fields) ⇒ BusinessObject
constructor
A new instance of BusinessObject.
- #post(data) ⇒ Object (also: #create)
- #put(data) ⇒ Object (also: #update)
- #put_fields(data) ⇒ Object (also: #patch)
Constructor Details
#initialize(**fields) ⇒ BusinessObject
Returns a new instance of BusinessObject.
11 12 13 |
# File 'lib/usps/imis/mocks/business_object.rb', line 11 def initialize(**fields) @fields = fields.transform_keys(&:to_s) end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
9 10 11 |
# File 'lib/usps/imis/mocks/business_object.rb', line 9 def fields @fields end |
Instance Method Details
#delete ⇒ Object Also known as: destroy
42 |
# File 'lib/usps/imis/mocks/business_object.rb', line 42 def delete = '' |
#get ⇒ Object Also known as: read
15 16 17 18 19 |
# File 'lib/usps/imis/mocks/business_object.rb', line 15 def get Usps::Imis::Properties.build do |props| fields.each { |name, value| props.add(name, value) } end end |
#get_field(name) ⇒ Object Also known as: fetch, []
22 |
# File 'lib/usps/imis/mocks/business_object.rb', line 22 def get_field(name) = fields[name] |
#get_fields(*field_names) ⇒ Object Also known as: fetch_all
26 |
# File 'lib/usps/imis/mocks/business_object.rb', line 26 def get_fields(*field_names) = field_names.map { fields[it] } |
#post(data) ⇒ Object Also known as: create
39 |
# File 'lib/usps/imis/mocks/business_object.rb', line 39 def post(data) = data |
#put(data) ⇒ Object Also known as: update
36 |
# File 'lib/usps/imis/mocks/business_object.rb', line 36 def put(data) = data |
#put_fields(data) ⇒ Object Also known as: patch
29 30 31 32 33 |
# File 'lib/usps/imis/mocks/business_object.rb', line 29 def put_fields(data) Usps::Imis::Properties.build do |props| fields.merge(data.transform_keys(&:to_s)).each { |name, value| props.add(name, value) } end end |