Class: MethodCall
- Inherits:
-
Object
- Object
- MethodCall
- Defined in:
- lib/method_call.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
Instance Method Summary collapse
- #evaluate_args(args_type, values) ⇒ Object
- #evaluate_method(args_type, service_name, method) ⇒ Object
-
#initialize(service_name, method, values) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #inspect_args ⇒ Object
- #inspect_methods(base_class) ⇒ Object
- #sample_call ⇒ Object
- #upcase_first(str) ⇒ Object
Constructor Details
#initialize(service_name, method, values) ⇒ MethodCall
Returns a new instance of MethodCall.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/method_call.rb', line 7 def initialize(service_name, method, values) eval(service_name) args_type = eval("#{service_name}::#{upcase_first(method)}_args") rescue nil evaluate_method(args_type, service_name, method) @inspector = ObjectInspector.new(args_type.new) args = evaluate_args(args_type, values) self.args = [method] + args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
5 6 7 |
# File 'lib/method_call.rb', line 5 def args @args end |
Instance Method Details
#evaluate_args(args_type, values) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/method_call.rb', line 28 def evaluate_args(args_type, values) args = TypeAdapter.new( { type: ::Thrift::Types::STRUCT, class: args_type }, values ).field_values rescue nil if args.nil? puts "Error processing args: #{values.to_json}\nExpected args:\n" pp inspect_args puts "\nExample argument with all optional fields:\n\n" puts sample_call exit 1 end args end |
#evaluate_method(args_type, service_name, method) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/method_call.rb', line 20 def evaluate_method(args_type, service_name, method) if args_type.nil? puts "\nMethod not found: #{method}\n\nThe following methods are available:" puts inspect_methods(service_name) exit 1 end end |
#inspect_args ⇒ Object
45 46 47 |
# File 'lib/method_call.rb', line 45 def inspect_args @inspector.args_tree end |
#inspect_methods(base_class) ⇒ Object
53 54 55 |
# File 'lib/method_call.rb', line 53 def inspect_methods(base_class) ObjectInspector.new(eval(base_class)).available_methods.join("\n") end |
#sample_call ⇒ Object
49 50 51 |
# File 'lib/method_call.rb', line 49 def sample_call @inspector.sample_call end |
#upcase_first(str) ⇒ Object
57 58 59 |
# File 'lib/method_call.rb', line 57 def upcase_first(str) str[0].upcase + str[1..-1] end |