Class: Quartz::GoStruct
- Inherits:
-
Object
- Object
- Quartz::GoStruct
- Defined in:
- lib/quartz/go_struct.rb
Instance Attribute Summary collapse
-
#struct_methods ⇒ Object
readonly
Returns the value of attribute struct_methods.
-
#struct_name ⇒ Object
readonly
Returns the value of attribute struct_name.
Instance Method Summary collapse
- #call(method_name, args = {}) ⇒ Object
-
#initialize(struct_name, method_info, process) ⇒ GoStruct
constructor
A new instance of GoStruct.
Constructor Details
#initialize(struct_name, method_info, process) ⇒ GoStruct
Returns a new instance of GoStruct.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/quartz/go_struct.rb', line 5 def initialize(struct_name, method_info, process) @struct_name = struct_name @method_name_to_arg_info = {} @process = process method_info["NameToMethodMetadata"].each do |method_name, info| @method_name_to_arg_info[method_name] = info["ArgumentToType"].keys() end @struct_methods = @method_name_to_arg_info.keys end |
Instance Attribute Details
#struct_methods ⇒ Object (readonly)
Returns the value of attribute struct_methods.
3 4 5 |
# File 'lib/quartz/go_struct.rb', line 3 def struct_methods @struct_methods end |
#struct_name ⇒ Object (readonly)
Returns the value of attribute struct_name.
3 4 5 |
# File 'lib/quartz/go_struct.rb', line 3 def struct_name @struct_name end |
Instance Method Details
#call(method_name, args = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quartz/go_struct.rb', line 17 def call(method_name, args = {}) unless @struct_methods.include?(method_name) raise Quartz::ArgumentError, "Invalid method: #{method_name}" end arg_info = @method_name_to_arg_info[method_name] # Validate arguments args.each do |k, v| unless arg_info.include?(k) raise Quartz::ArgumentError, "Invalid argument: #{k}" end # TODO: validate types end response = @process.call(@struct_name, method_name, args) if response['error'] raise Quartz::ResponseError.new(response['error']) end response['result'] end |