Class: CF::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cf/resources/base.rb

Class Method Summary collapse

Class Method Details

.clientObject



7
8
9
# File 'lib/cf/resources/base.rb', line 7

def client
  CF.client
end

.create(attributes = {}, params = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cf/resources/base.rb', line 23

def create(attributes = {}, params = {})
  # Extract parent IDs from attributes based on path convention
  extracted_params = extract_parent_ids_from_attributes(attributes)
  attributes = extracted_params[:attributes]
  params = params.merge(extracted_params[:params])
  
  path = build_path("create", nil, params)
  query_params = params.reject { |k, _v| parent_id_param?(k) }
  wrapped_attributes = wrap_attributes_for_request(attributes)
  client.post(path, wrapped_attributes, query_params)
end

.delete(id, params = {}) ⇒ Object



47
48
49
50
51
# File 'lib/cf/resources/base.rb', line 47

def delete(id, params = {})
  path = build_path("delete", id, params)
  query_params = params.reject { |k, _v| parent_id_param?(k) }
  client.delete(path, query_params)
end

.get(id, params = {}) ⇒ Object



17
18
19
20
21
# File 'lib/cf/resources/base.rb', line 17

def get(id, params = {})
  path = build_path("get", id, params)
  query_params = params.reject { |k, _v| parent_id_param?(k) }
  client.get(path, query_params)
end

.list(params = {}) ⇒ Object



11
12
13
14
15
# File 'lib/cf/resources/base.rb', line 11

def list(params = {})
  path = build_path("list", nil, params)
  query_params = params.reject { |k, _v| parent_id_param?(k) }
  client.get(path, query_params)
end

.update(id, attributes = {}, params = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cf/resources/base.rb', line 35

def update(id, attributes = {}, params = {})
  # Extract parent IDs from attributes based on path convention
  extracted_params = extract_parent_ids_from_attributes(attributes)
  attributes = extracted_params[:attributes]
  params = params.merge(extracted_params[:params])
  
  path = build_path("update", id, params)
  query_params = params.reject { |k, _v| parent_id_param?(k) }
  wrapped_attributes = wrap_attributes_for_request(attributes)
  client.patch(path, wrapped_attributes, query_params)
end