Class: Collins::AssetClient
- Inherits:
-
Object
- Object
- Collins::AssetClient
- Defined in:
- lib/collins/asset_client.rb
Overview
Convenience class for making collins calls for only a single asset
Instance Method Summary collapse
-
#initialize(asset, client, logger) ⇒ AssetClient
constructor
A new instance of AssetClient.
-
#method_missing(meth, *args, &block) ⇒ Object
Fill in the missing asset parameter on the dynamic method if needed.
- #respond_to?(meth, include_private = false) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(asset, client, logger) ⇒ AssetClient
Returns a new instance of AssetClient.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/collins/asset_client.rb', line 6 def initialize asset, client, logger @asset = asset if asset.is_a?(Collins::Asset) then @tag = asset.tag else @tag = asset end @client = client @logger = logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Note:
this method should never be called directly
Fill in the missing asset parameter on the dynamic method if needed
If 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 Client does not respond to the method, we defer to `super`.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/collins/asset_client.rb', line 33 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 |
Instance Method Details
#respond_to?(meth, include_private = false) ⇒ Boolean
51 52 53 |
# File 'lib/collins/asset_client.rb', line 51 def respond_to? meth, include_private = false @client.respond_to?(meth) end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/collins/asset_client.rb', line 17 def to_s "AssetClient(asset = #{@tag}, client = #{@client})" end |