Sha256: 1c456b4e742ce0a2566a4f88f8a8de3e43c84ac053e4cd935466e3503e3bef13

Contents?: true

Size: 805 Bytes

Versions: 5

Compression:

Stored size: 805 Bytes

Contents

module ObjectAttorney
  module Helpers
    module_function

    def marked_for_destruction?(object)
      return false unless object.respond_to?(:marked_for_destruction?)

      object.marked_for_destruction?
    end

    def call_proc_or_method(base, proc_or_method, object = nil)
      if proc_or_method.is_a?(Proc)
        base.instance_exec(object, &proc_or_method)
      else
        call_method!(base, proc_or_method, object)
      end
    end

    def call_method!(base, method, *args)
      unless base.respond_to?(method)
        raise NotImplementedError, "#{base} does not respond to #{method}"
      end

      base.send(method, *args)
    end

    def extend_errors_if_necessary(object)
      return if object.respond_to?(:errors)

      object.class.send(:include, Errors)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
object_attorney-3.2.0 lib/object_attorney/helpers.rb
object_attorney-3.1.2 lib/object_attorney/helpers.rb
object_attorney-3.1.1 lib/object_attorney/helpers.rb
object_attorney-3.1.0 lib/object_attorney/helpers.rb
object_attorney-3.0.7 lib/object_attorney/helpers.rb