Module: Fakie::JavaScript

Defined in:
lib/fakie/java_script.rb

Class Method Summary collapse

Class Method Details

.call(function, *args) ⇒ Object

Call a function against the context

Parameters:

  • function (String)

    function name

  • args (* String)

    list of arguments to send to the function



20
21
22
# File 'lib/fakie/java_script.rb', line 20

def call(function, *args)
  context.call(function, *args)
end

.contextExecJS::ExternalRuntime::Context

ExecJS Context

Returns:

  • (ExecJS::ExternalRuntime::Context)

    context for executing JavaScript against libphonenumber and Fakie



7
8
9
10
11
12
13
14
15
# File 'lib/fakie/java_script.rb', line 7

def context
  @@_js_context ||= begin
    require 'execjs'
    js_dir = File.join(File.expand_path(File.dirname(__FILE__)), 'js')
    source = File.open(File.join(js_dir, 'libphonenumber.js')).read
    source += File.open(File.join(js_dir, 'fakie.js')).read
    ExecJS.compile(source)
  end
end

.eval(script) ⇒ Object

Call a function against the context

Parameters:

  • function (String)

    JavaScript code to evaluate



26
27
28
# File 'lib/fakie/java_script.rb', line 26

def eval(script)
  context.eval(script)
end