Module: EvernoteOAuth::ThriftClientDelegation
- Defined in:
- lib/evernote_oauth/thrift_client_delegation.rb
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/evernote_oauth/thrift_client_delegation.rb', line 4 def method_missing(name, *args, &block) method = @client.class.instance_method(name) parameters = method.parameters if parameters.size != args.size && idx_token = parameters.index{|e| e.last == :authenticationToken} new_args = args.dup.insert(idx_token, @token) begin result = @client.send(name, *new_args, &block) rescue ArgumentError => e result = @client.send(name, *args, &block) end else result = @client.send(name, *args, &block) end attr_value = self [result].flatten.each{|r| begin r.define_singleton_method(attr_name){attr_value} rescue TypeError # Fixnum/TrueClass/FalseClass/NilClass next end } result end |