support/ruby/collins-client/lib/collins/asset_client.rb
# Fill in the missing asset parameter on the dynamic method if needed
#
# If {Collins::Client} responds to the method, and the method requires an `asset_or_tag`, we
# insert the asset specified during initialization into the args array. If the method does not
# require an `asset_or_tag`, we simply proxy the method call as is. If {Collins::Client} does
# not respond to the method, we defer to `super`.
#
# @example
#   collins_client.get('some_tag')            # => returns that asset
#   collins_client.with_asset('some_tag').get # => returns that same asset
#
# @note this method should never be called directly
Fill in the missing asset parameter on the dynamic method if needed
If {Collins::Client} responds to the method, and the method requires an `asset_or_tag`, we
insert the asset specified during initialization into the args array. If the method does not
require an `asset_or_tag`, we simply proxy the method call as is. If {Collins::Client} does
not respond to the method, we defer to `super`.
Fill in the missing asset parameter on the dynamic method if needed If { Collins :: Client } responds to the method and the method requires an ` asset_or_tag ` we insert the asset specified during initialization into the args array . If the method does not require an ` asset_or_tag ` we simply proxy the method call as is . If { Collins :: Client } does not respond to the method we defer to ` super ` .
def method_missing meth, *args, &block
      if @client.respond_to?(meth) then
        method_parameters = @client.class.instance_method(meth).parameters
        asset_idx = method_parameters.find_index do |item|
          item[1] == :asset_or_tag
        end
        if asset_idx.nil? then
          @client.send(meth, *args, &block)
        else
          args_with_asset = args.insert(asset_idx, @tag)
          logger.debug("Doing #{meth}(#{args_with_asset.join(',')}) for #{@tag}")
          @client.send(meth, *args_with_asset, &block)
        end
      else
        super
      end
    end
def method_missing meth , * args , & block if @client . respond_to? ( meth ) then method_parameters = @client . class . instance_method ( meth ) . parameters asset_idx = method_parameters . find_index do | item | item [ 1 ] == :asset_or_tag end if asset_idx . nil? then @client . send ( meth , * args , & block ) else args_with_asset = args . insert ( asset_idx , @tag ) logger . debug ( "Doing #{meth}(#{args_with_asset.join(',')}) for #{@tag}" ) @client . send ( meth , * args_with_asset , & block ) end else super end end
Fill in the missing asset parameter on the dynamic method if needed
If {Collins::Client} responds to the method, and the method requires an `asset_or_tag`, we
insert the asset specified during initialization into the args array.
Fill in the missing asset parameter on the dynamic method if needed If { Collins :: Client } responds to the method and the method requires an ` asset_or_tag ` we insert the asset specified during initialization into the args array .
meth
args
block
example
collins_client.get('some_tag') # => returns that asset collins_client.with_asset('some_tag').get # => returns that same asset
collins_client . get ( ' some_tag ' ) # = > returns that asset collins_client . with_asset ( ' some_tag ' ) . get # = > returns that same asset
note
this method should never be called directly
this method should never be called directly