Class: SgNodeMapper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sg_node_mapper.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.

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

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.



31
32
33
# File 'lib/sg_node_mapper.rb', line 31

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

Instance Method Details

#contextObject

Get a (potentially cached) version of the compiled source code for sgNodeMapper.

Returns an ExecJS::ExternalRuntime::Context.



38
39
40
# File 'lib/sg_node_mapper.rb', line 38

def context
  @context ||= ExecJS.compile(source)
end