Class: Velocity::Instance::APIModel

Inherits:
Object
  • Object
show all
Defined in:
lib/acceleration/velocity.rb

Overview

The APIModel is a very simple interface for building more complex API function models. It shouldn’t ever be instantiated itself.

TODO: refactor some of this method into something includable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ APIModel

Create a new APIModel instance



257
258
259
# File 'lib/acceleration/velocity.rb', line 257

def initialize(instance)
  @instance = instance
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(function, *args) ⇒ Object

This magical method enables a direct pass-through of methods if no special logic is required to handle the response.



282
283
284
285
286
# File 'lib/acceleration/velocity.rb', line 282

def method_missing(function, *args)
  instance.call resolve(function), args
rescue
  super
end

Instance Attribute Details

#instanceObject

A handle on the instance



253
254
255
# File 'lib/acceleration/velocity.rb', line 253

def instance
  @instance
end

Instance Method Details

#resolve(operation) ⇒ Object

Build the API function name based off the prefix and the desired operation.



265
266
267
# File 'lib/acceleration/velocity.rb', line 265

def resolve(operation)
  [prefix, operation.dasherize].join '-'
end

#respond_to_missing?(_function, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


288
289
290
# File 'lib/acceleration/velocity.rb', line 288

def respond_to_missing?(_function, _include_private = false)
  true
end