Class: HaveAPI::GoClient::Action

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/haveapi/go_client/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#camelize

Constructor Details

#initialize(resource, name, desc, prefix: nil) ⇒ Action



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/haveapi/go_client/action.rb', line 57

def initialize(resource, name, desc, prefix: nil)
  @resource = resource
  @name = name.to_s
  @prefix = prefix
  @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]
   = desc[:meta] && .new(self, desc[:meta])
  @blocking = desc[:blocking]
end

Instance Attribute Details

#aliasesArray<String> (readonly)

Name aliases as returned by the API



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

def aliases
  @aliases
end

#full_dot_nameString (readonly)

Full action name, including resource



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

def full_dot_name
  @full_dot_name
end

#go_invocation_typeString (readonly)

Go type for invocation struct



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

def go_invocation_type
  @go_invocation_type
end

#go_nameString (readonly)

Name for usage in Go



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

def go_name
  @go_name
end

#go_request_typeString (readonly)

Go type for request struct



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

def go_request_type
  @go_request_type
end

#go_response_typeString (readonly)

Go type for response struct



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

def go_response_type
  @go_response_type
end

#go_typeString (readonly)

Data type for Go



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

def go_type
  @go_type
end

#http_methodString (readonly)



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

def http_method
  @http_method
end

#inputInputOutput (readonly)



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

def input
  @input
end

#metadataMetadata (readonly)



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

def 
  
end

#nameString (readonly)

Name as returned by the API



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

def name
  @name
end

#outputInputOutput (readonly)



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

def output
  @output
end

#pathString (readonly)



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

def path
  @path
end

#resourceResource (readonly)



8
9
10
# File 'lib/haveapi/go_client/action.rb', line 8

def resource
  @resource
end

Instance Method Details

#<=>(other) ⇒ Object



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

def <=>(other)
  go_name <=> other.go_name
end

#all_names {|go_name| ... } ⇒ Array<String>

Return action name with all aliases, camelized

Yields:



78
79
80
81
# File 'lib/haveapi/go_client/action.rb', line 78

def all_names
  yield(go_name)
  aliases.each { |v| yield(camelize(v)) }
end

#blocking?Boolean



104
105
106
# File 'lib/haveapi/go_client/action.rb', line 104

def blocking?
  @blocking
end

#has_input?Boolean



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

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

#has_output?Boolean



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

def has_output?
  output && output.parameters.any?
end

#has_path_params?Boolean



84
85
86
# File 'lib/haveapi/go_client/action.rb', line 84

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

#input_outputObject



98
99
100
101
102
# File 'lib/haveapi/go_client/action.rb', line 98

def input_output
  i[input output].select do |v|
    send(v) && send(v).parameters.any?
  end.map { |v| send(v) }
end

#resolve_associationsObject



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

def resolve_associations
  input_output.each(&:resolve_associations)

   && .resolve_associations
end