Sha256: 939fb41899c5d93faa3dc874458b6a325053bb40d5b3de308e6a2f3292654901

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

require 'holmes/version'
require 'execjs'

module Holmes extend self
  def parse(data, options = {})
    context.call('find', data, options)
  end

  def find(src, options = {})
    data   = File.read(src)
    result = parse(data, options)
    raise 'Dynamic require calls' if result['expressions'].any?
    result['strings']
  end

  protected
    def context
      @context ||= backend.compile(script)
    end

    def script
      File.read(File.expand_path('../holmes/require.js', __FILE__))
    end

    def backend
      @backend ||= ExecJS::ExternalRuntime.new(
        :name        => 'Node.js (V8)',
        :command     => ['nodejs', 'node'],
        :runner_path => File.expand_path('../holmes/runner.js', __FILE__)
      )
    end

    def bundled_path
      File.expand_path('../holmes/node_modules', __FILE__)
    end

    ENV['NODE_PATH'] = "#{File.expand_path('node_modules')}:#{bundled_path}:#{ENV['NODE_PATH']}"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
holmes-0.0.1 lib/holmes.rb