Sha256: f6fcb378742e51e59ac2f3137f4e2d4d66cf8edb55fbb91ea521702891b23df0

Contents?: true

Size: 648 Bytes

Versions: 2

Compression:

Stored size: 648 Bytes

Contents

# frozen_string_literal: true

if ActiveObject.configuration.autoload_kernel
  module Kernel

    SANITIZE_EVAL_REGEX ||= /\[\d*,?\d*,?\d*\]/.freeze
    CALLER_METHOD_REGEX ||= /`([^']*)'/.freeze

    # rubocop:disable Security/Eval
    def safe_eval
      eval(self)
    rescue Exception
      self
    end

    def try_eval
      val = SANITIZE_EVAL_REGEX.match(to_s).to_s
      return if val.nil?

      eval(val)
    end
    # rubocop:enable Security/Eval

    private

    # rubocop:disable Style/PerlBackrefs
    def caller_name
      caller(1..1).first =~ CALLER_METHOD_REGEX && $1
    end
    # rubocop:enable Style/PerlBackrefs

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_object-5.8.1 lib/active_object/kernel.rb
active_object-5.8.0 lib/active_object/kernel.rb