Sha256: 150c596bd68b4639e1ee03f01b7de841d59717c24f15fe49fb751081a46e2cdc

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

module Thinreports
  module Utils
    def self.included(klass)
      klass.extend self
    end

    def deep_copy(src)
      case src
      when Hash
        src.each_with_object({}) do |(k, v), h|
          h[k] = v.dup rescue v # rubocop:disable Lint/RescueWithoutErrorClass,Lint/RescueModifier
        end
      when Array
        src.map do |a|
          a.dup rescue a # rubocop:disable Lint/RescueWithoutErrorClass,Lint/RescueModifier
        end
      else
        raise ArgumentError
      end
    end

    def blank_value?(value)
      case value
      when String   then value.empty?
      when NilClass then true
      else false
      end
    end

    def call_block_in(scope, &block)
      return scope unless block_given?

      if block.arity == 1
        block.call(scope)
      else
        scope.instance_eval(&block)
      end
      scope
    end
  end

  extend Utils
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinreports-0.10.1 lib/thinreports/core/utils.rb