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.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/haveapi/go_client/action.rb', line 61
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
51
52
53
|
# File 'lib/haveapi/go_client/action.rb', line 51
def go_invocation_type
@go_invocation_type
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
55
56
57
|
# File 'lib/haveapi/go_client/action.rb', line 55
def go_request_type
@go_request_type
end
|
#go_response_type ⇒ String
Go type for response struct
59
60
61
|
# File 'lib/haveapi/go_client/action.rb', line 59
def go_response_type
@go_response_type
end
|
#go_type ⇒ String
32
33
34
|
# File 'lib/haveapi/go_client/action.rb', line 32
def go_type
@go_type
end
|
#http_method ⇒ String
44
45
46
|
# File 'lib/haveapi/go_client/action.rb', line 44
def http_method
@http_method
end
|
38
39
40
|
# File 'lib/haveapi/go_client/action.rb', line 38
def input
@input
end
|
35
36
37
|
# File 'lib/haveapi/go_client/action.rb', line 35
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
|
41
42
43
|
# File 'lib/haveapi/go_client/action.rb', line 41
def output
@output
end
|
#path ⇒ String
47
48
49
|
# File 'lib/haveapi/go_client/action.rb', line 47
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
118
119
120
|
# File 'lib/haveapi/go_client/action.rb', line 118
def <=>(other)
go_name <=> other.go_name
end
|
#all_names ⇒ Array<String>
Return action name with all aliases, camelized
83
84
85
|
# File 'lib/haveapi/go_client/action.rb', line 83
def all_names(&)
([go_name] + aliases.map { |v| camelize(v) }).uniq.each(&)
end
|
#blocking? ⇒ Boolean
108
109
110
|
# File 'lib/haveapi/go_client/action.rb', line 108
def blocking?
@blocking
end
|
93
94
95
|
# File 'lib/haveapi/go_client/action.rb', line 93
def has_input?
input && input.parameters.any?
end
|
#has_output? ⇒ Boolean
98
99
100
|
# File 'lib/haveapi/go_client/action.rb', line 98
def has_output?
output && output.parameters.any?
end
|
#has_path_params? ⇒ Boolean
88
89
90
|
# File 'lib/haveapi/go_client/action.rb', line 88
def has_path_params?
path =~ /\{[a-zA-Z0-9\-_]+\}/
end
|
102
103
104
105
106
|
# File 'lib/haveapi/go_client/action.rb', line 102
def input_output
%i[input output].select do |v|
send(v) && send(v).parameters.any?
end.map { |v| send(v) }
end
|
#resolve_associations ⇒ Object
112
113
114
115
116
|
# File 'lib/haveapi/go_client/action.rb', line 112
def resolve_associations
input_output.each(&:resolve_associations)
metadata && metadata.resolve_associations
end
|