11require_relative 'base_presenter'
2+ require 'presenters/mixins/last_operation_helper'
23
34module VCAP
45 module CloudController
56 module Presenters
67 module V3
78 class ServiceCredentialBindingPresenter < BasePresenter
9+ include VCAP ::CloudController ::Presenters ::Mixins ::LastOperationHelper
10+
811 def to_hash
912 base_hash . merge ( extra ) . merge ( decorations )
1013 end
1114
1215 private
1316
17+ def binding
18+ @resource
19+ end
20+
1421 def base_hash
1522 {
16- guid : @resource . guid ,
17- created_at : @resource . created_at ,
18- updated_at : @resource . updated_at ,
19- name : @resource . name ,
20- type : type
23+ guid : binding . guid ,
24+ created_at : binding . created_at ,
25+ updated_at : binding . updated_at ,
26+ name : binding . name ,
27+ type : type ,
28+ last_operation : last_operation ( binding ) ,
2129 }
2230 end
2331
2432 def decorations
25- @decorators . reduce ( { } ) { |memo , d | d . decorate ( memo , [ @resource ] ) }
33+ @decorators . reduce ( { } ) { |memo , d | d . decorate ( memo , [ binding ] ) }
2634 end
2735
2836 def type
29- case @resource
37+ case binding
3038 when VCAP ::CloudController ::ServiceKey
3139 'key'
3240 when VCAP ::CloudController ::ServiceBinding
@@ -38,65 +46,49 @@ def extra
3846 case type
3947 when 'app'
4048 {
41- last_operation : last_operation ,
4249 relationships : base_relationships . merge ( app_relationship ) ,
4350 links : base_links . merge ( app_link )
4451 }
4552 when 'key'
4653 {
47- last_operation : nil ,
4854 relationships : base_relationships ,
4955 links : base_links
5056 }
5157 end
5258 end
5359
54- def last_operation
55- return nil if @resource . last_operation . blank?
56-
57- last_operation = @resource . last_operation
58-
59- {
60- type : last_operation . type ,
61- state : last_operation . state ,
62- description : last_operation . description ,
63- created_at : last_operation . created_at ,
64- updated_at : last_operation . updated_at
65- }
66- end
67-
6860 def base_links
69- parameters = { parameters : "#{ path_to_self } /parameters" } unless @resource . service_instance . user_provided_instance?
61+ parameters = { parameters : "#{ path_to_self } /parameters" } unless binding . service_instance . user_provided_instance?
7062
7163 {
7264 self : path_to_self ,
7365 details : "#{ path_to_self } /details" ,
74- service_instance : "/v3/service_instances/#{ @resource . service_instance_guid } "
66+ service_instance : "/v3/service_instances/#{ binding . service_instance_guid } "
7567 } . merge ( parameters || { } ) . transform_values do |path |
7668 hrefify ( path )
7769 end
7870 end
7971
8072 def path_to_self
81- "/v3/service_credential_bindings/#{ @resource . guid } "
73+ "/v3/service_credential_bindings/#{ binding . guid } "
8274 end
8375
8476 def base_relationships
8577 {
86- service_instance : { data : { guid : @resource . service_instance_guid } }
78+ service_instance : { data : { guid : binding . service_instance_guid } }
8779 }
8880 end
8981
9082 def app_relationship
91- return { } if @resource . app_guid . blank?
83+ return { } if binding . app_guid . blank?
9284
93- { app : { data : { guid : @resource . app_guid } } }
85+ { app : { data : { guid : binding . app_guid } } }
9486 end
9587
9688 def app_link
97- return { } if @resource . app_guid . blank?
89+ return { } if binding . app_guid . blank?
9890
99- { app : hrefify ( "/v3/apps/#{ @resource . app_guid } " ) }
91+ { app : hrefify ( "/v3/apps/#{ binding . app_guid } " ) }
10092 end
10193
10294 def hrefify ( path )
0 commit comments