Class: SgNodeMapper

Inherits:
Object
  • Object
show all
Includes:
Caching, Singleton
Defined in:
lib/sg_node_mapper.rb,
lib/sg_node_mapper/caching.rb,
lib/sg_node_mapper/version.rb

Overview

Simple wrapper for the sgNodeMapper javascript library. Uses [ExecJS](github.com/sstephenson/execjs) to dynamically select the best available javascript platform to execute the code on.

This class will dynamically call methods in the sgNodeMapper javascript library. In the case that the the method doesn’t exist, it will return nil, rather than raising a NoMethodError, this is a side effect of blindly delegating to javascript.

Defined Under Namespace

Modules: Caching Classes: Error

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



39
40
41
42
43
# File 'lib/sg_node_mapper.rb', line 39

def method_missing(method, *args)
  cache_and_return method, *args do
    context.call("nodemapper.#{method.to_s.camelize(:lower)}", *args)
  end
end

Class Method Details

.method_missing(method, *args) ⇒ Object

When a method is called on this class, we intercept it and pass it through to the javascript context by converting the method name from underscore_case to camelCase, then calling that method on the javascript context with the given *args.

method - The Symbol name of the method being called. args - The Array of arguments (optional).

Returns the result from javascript.



35
36
37
# File 'lib/sg_node_mapper.rb', line 35

def self.method_missing(method, *args)
  instance.send(method, *args)
end