Sha256: 17bff7e1409008b02bb039f048eabe5d88feedc72e95c2815cb1c7ccf3cfa12e

Contents?: true

Size: 495 Bytes

Versions: 1

Compression:

Stored size: 495 Bytes

Contents

# frozen_string_literal: true

module SimpleJson
  class SimpleJsonTemplate
    def initialize(path)
      @path = path
      @source = File.read(path)
    end

    def renderer
      @renderer ||= eval(code, TOPLEVEL_BINDING, @path) # rubocop:disable Security/Eval
    end

    def code
      @code ||= lambda_stringify(@source)
    end

    private

    def lambda_stringify(source)
      return source if source.match?(/^(?:\s*(?:#.*?)?\n)*\s*->/)

      "-> { #{source} }"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_json-0.0.0 lib/simple_json/simple_json_template.rb