module TurfJS

Public Class Methods

context() click to toggle source
# File lib/turfjs.rb, line 8
def self.context
  @context ||=
    begin
      source = File.read(File.expand_path('turfjs-build.js', __dir__))
      ExecJS.compile(source)
    end
end
method_missing(method, *args) click to toggle source
Calls superclass method
# File lib/turfjs.rb, line 23
def self.method_missing(method, *args)
  turf_api_name = turf_api_mapping[method]
  return super unless turf_api_name

  begin
    context.call("turf.#{turf_api_name}", *args)
  rescue ExecJS::ProgramError => e
    raise Error, e.message
  end
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/turfjs.rb, line 34
def self.respond_to_missing?(method, include_private = false)
  turf_api_mapping.keys.include?(method) || super
end
turf_api_mapping() click to toggle source
# File lib/turfjs.rb, line 16
def self.turf_api_mapping
  @turf_api_mapping ||=
    context.call('turfAPIs').map do |name|
      [name.underscore.to_sym, name]
    end.to_h
end