Sha256: dd852065bd5edf910f944d39316f61e21bfb9b4ba6ce5130cc0cbb94b11a2eb6

Contents?: true

Size: 692 Bytes

Versions: 14

Compression:

Stored size: 692 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

    def caller_name(depth = 0)
      val = caller[depth][CALLER_METHOD_REGEX, 1]
      return val if depth.zero? || !val.include?('<top (required)>')

      caller[depth - 1][CALLER_METHOD_REGEX, 1]
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
active_object-5.14.1 lib/active_object/kernel.rb
active_object-5.14.0 lib/active_object/kernel.rb
active_object-5.13.0 lib/active_object/kernel.rb
active_object-5.12.0 lib/active_object/kernel.rb
active_object-5.11.0 lib/active_object/kernel.rb
active_object-5.10.0 lib/active_object/kernel.rb
active_object-5.9.0 lib/active_object/kernel.rb
active_object-5.8.11 lib/active_object/kernel.rb
active_object-5.8.10 lib/active_object/kernel.rb
active_object-5.8.9 lib/active_object/kernel.rb
active_object-5.8.8 lib/active_object/kernel.rb
active_object-5.8.7 lib/active_object/kernel.rb
active_object-5.8.6 lib/active_object/kernel.rb
active_object-5.8.5 lib/active_object/kernel.rb