Class: HaveAPI::GoClient::Action

Inherits:
Object
  • Object
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

#aliasesArray<String> (readonly)

Name aliases as returned by the API

Returns:

  • (Array<String>)


16
17
18
# File 'lib/haveapi/go_client/action.rb', line 16

def aliases
  @aliases
end

#file_nameString (readonly)

Safe name for generated filenames

Returns:

  • (String)


20
21
22
# File 'lib/haveapi/go_client/action.rb', line 20

def file_name
  @file_name
end

#full_dot_nameString (readonly)

Full action name, including resource

Returns:

  • (String)


24
25
26
# File 'lib/haveapi/go_client/action.rb', line 24

def full_dot_name
  @full_dot_name
end

#go_invocation_typeString (readonly)

Go type for invocation struct

Returns:

  • (String)


51
52
53
# File 'lib/haveapi/go_client/action.rb', line 51

def go_invocation_type
  @go_invocation_type
end

#go_nameString (readonly)

Name for usage in Go

Returns:

  • (String)


28
29
30
# File 'lib/haveapi/go_client/action.rb', line 28

def go_name
  @go_name
end

#go_request_typeString (readonly)

Go type for request struct

Returns:

  • (String)


55
56
57
# File 'lib/haveapi/go_client/action.rb', line 55

def go_request_type
  @go_request_type
end

#go_response_typeString (readonly)

Go type for response struct

Returns:

  • (String)


59
60
61
# File 'lib/haveapi/go_client/action.rb', line 59

def go_response_type
  @go_response_type
end

#go_typeString (readonly)

Data type for Go

Returns:

  • (String)


32
33
34
# File 'lib/haveapi/go_client/action.rb', line 32

def go_type
  @go_type
end

#http_methodString (readonly)

Returns:

  • (String)


44
45
46
# File 'lib/haveapi/go_client/action.rb', line 44

def http_method
  @http_method
end

#inputInputOutput (readonly)

Returns:



38
39
40
# File 'lib/haveapi/go_client/action.rb', line 38

def input
  @input
end

#metadataMetadata (readonly)

Returns:



35
36
37
# File 'lib/haveapi/go_client/action.rb', line 35

def 
  @metadata
end

#nameString (readonly)

Name as returned by the API

Returns:

  • (String)


12
13
14
# File 'lib/haveapi/go_client/action.rb', line 12

def name
  @name
end

#outputInputOutput (readonly)

Returns:



41
42
43
# File 'lib/haveapi/go_client/action.rb', line 41

def output
  @output
end

#pathString (readonly)

Returns:

  • (String)


47
48
49
# File 'lib/haveapi/go_client/action.rb', line 47

def path
  @path
end

#resourceResource (readonly)

Returns:



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_namesArray<String>

Return action name with all aliases, camelized

Returns:

  • (Array<String>)


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

Returns:

  • (Boolean)


108
109
110
# File 'lib/haveapi/go_client/action.rb', line 108

def blocking?
  @blocking
end

#has_input?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/haveapi/go_client/action.rb', line 93

def has_input?
  input && input.parameters.any?
end

#has_output?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


88
89
90
# File 'lib/haveapi/go_client/action.rb', line 88

def has_path_params?
  path =~ /\{[a-zA-Z0-9\-_]+\}/
end

#input_outputObject



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_associationsObject



112
113
114
115
116
# File 'lib/haveapi/go_client/action.rb', line 112

def resolve_associations
  input_output.each(&:resolve_associations)

   && .resolve_associations
end