Class: HaveAPI::GoClient::Action
- Inherits:
-
Object
- Object
- HaveAPI::GoClient::Action
show all
- Includes:
- Utils
- Defined in:
- lib/haveapi/go_client/action.rb
Constant Summary
Constants included
from Utils
Utils::GO_KEYWORDS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#camelize, #go_comment_text, #go_json_tag, #go_module_path, #go_package_name, #go_query_key, #go_string_literal, #safe_file_component
Constructor Details
#initialize(resource, name, desc, prefix: nil) ⇒ Action
Returns a new instance of Action.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/haveapi/go_client/action.rb', line 65
def initialize(resource, name, desc, prefix: nil)
@resource = resource
@name = name.to_s
@prefix = prefix
@file_name = safe_file_component(@name)
@aliases = desc[:aliases]
@full_dot_name = "#{resource.full_dot_name}##{@name.capitalize}"
@go_name = camelize(name)
@go_type = full_go_type
@go_invocation_type = "#{go_type}Invocation"
@go_request_type = "#{go_type}Request"
@go_response_type = "#{go_type}Response"
@input = desc[:input] && InputOutput.new(self, :io, :input, desc[:input])
@output = desc[:output] && InputOutput.new(self, :io, :output, desc[:output])
@http_method = desc[:method]
@path = desc[:path]
@metadata = desc[:meta] && Metadata.new(self, desc[:meta])
@blocking = desc[:blocking]
end
|
Instance Attribute Details
#aliases ⇒ Array<String>
Name aliases as returned by the API
16
17
18
|
# File 'lib/haveapi/go_client/action.rb', line 16
def aliases
@aliases
end
|
#file_name ⇒ String
Safe name for generated filenames
20
21
22
|
# File 'lib/haveapi/go_client/action.rb', line 20
def file_name
@file_name
end
|
#full_dot_name ⇒ String
Full action name, including resource
24
25
26
|
# File 'lib/haveapi/go_client/action.rb', line 24
def full_dot_name
@full_dot_name
end
|
#go_invocation_type ⇒ String
Go type for invocation struct
55
56
57
|
# File 'lib/haveapi/go_client/action.rb', line 55
def go_invocation_type
@go_invocation_type
end
|
#go_member_names ⇒ Array<String>
Names of fields for the action and its aliases in the resource Go struct
32
33
34
|
# File 'lib/haveapi/go_client/action.rb', line 32
def go_member_names
@go_member_names
end
|
#go_name ⇒ String
28
29
30
|
# File 'lib/haveapi/go_client/action.rb', line 28
def go_name
@go_name
end
|
#go_request_type ⇒ String
Go type for request struct
59
60
61
|
# File 'lib/haveapi/go_client/action.rb', line 59
def go_request_type
@go_request_type
end
|
#go_response_type ⇒ String
Go type for response struct
63
64
65
|
# File 'lib/haveapi/go_client/action.rb', line 63
def go_response_type
@go_response_type
end
|
#go_type ⇒ String
36
37
38
|
# File 'lib/haveapi/go_client/action.rb', line 36
def go_type
@go_type
end
|
#http_method ⇒ String
48
49
50
|
# File 'lib/haveapi/go_client/action.rb', line 48
def http_method
@http_method
end
|
42
43
44
|
# File 'lib/haveapi/go_client/action.rb', line 42
def input
@input
end
|
39
40
41
|
# File 'lib/haveapi/go_client/action.rb', line 39
def metadata
@metadata
end
|
#name ⇒ String
Name as returned by the API
12
13
14
|
# File 'lib/haveapi/go_client/action.rb', line 12
def name
@name
end
|
45
46
47
|
# File 'lib/haveapi/go_client/action.rb', line 45
def output
@output
end
|
#path ⇒ String
51
52
53
|
# File 'lib/haveapi/go_client/action.rb', line 51
def path
@path
end
|
8
9
10
|
# File 'lib/haveapi/go_client/action.rb', line 8
def resource
@resource
end
|
Instance Method Details
#<=>(other) ⇒ Object
143
144
145
|
# File 'lib/haveapi/go_client/action.rb', line 143
def <=>(other)
[go_name, name] <=> [other.go_name, other.name]
end
|
#all_names ⇒ Array<String>
Return allocated action member names, including aliases.
87
88
89
|
# File 'lib/haveapi/go_client/action.rb', line 87
def all_names(&)
go_member_names.each(&)
end
|
#allocate_member_names(allocator) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/haveapi/go_client/action.rb', line 97
def allocate_member_names(allocator)
@go_member_names = ([name] + aliases.map(&:to_s)).uniq.map do |raw_name|
allocator.allocate(
camelize(raw_name),
suffix: 'Action',
identity: [
'action',
resource.resource_path.map(&:name).join('/'),
name,
raw_name
].join(':')
)
end
end
|
#blocking? ⇒ Boolean
133
134
135
|
# File 'lib/haveapi/go_client/action.rb', line 133
def blocking?
@blocking
end
|
#go_member_name ⇒ String
92
93
94
|
# File 'lib/haveapi/go_client/action.rb', line 92
def go_member_name
go_member_names.first
end
|
118
119
120
|
# File 'lib/haveapi/go_client/action.rb', line 118
def has_input?
input && input.parameters.any?
end
|
#has_output? ⇒ Boolean
123
124
125
|
# File 'lib/haveapi/go_client/action.rb', line 123
def has_output?
output && output.parameters.any?
end
|
#has_path_params? ⇒ Boolean
113
114
115
|
# File 'lib/haveapi/go_client/action.rb', line 113
def has_path_params?
path =~ /\{[a-zA-Z0-9\-_]+\}/
end
|
127
128
129
130
131
|
# File 'lib/haveapi/go_client/action.rb', line 127
def input_output
%i[input output].select do |v|
send(v) && send(v).parameters.any?
end.map { |v| send(v) }
end
|
#resolve_associations ⇒ Object
137
138
139
140
141
|
# File 'lib/haveapi/go_client/action.rb', line 137
def resolve_associations
input_output.each(&:resolve_associations)
metadata && metadata.resolve_associations
end
|