Module: ObjectAttorney::Helpers

Defined in:
lib/object_attorney/helpers.rb

Class Method Summary collapse

Class Method Details

.call_method!(base, method, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/object_attorney/helpers.rb', line 19

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

.call_proc_or_method(base, proc_or_method, object = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/object_attorney/helpers.rb', line 11

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

.extend_errors_if_necessary(object) ⇒ Object



27
28
29
30
31
# File 'lib/object_attorney/helpers.rb', line 27

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

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

.marked_for_destruction?(object) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/object_attorney/helpers.rb', line 5

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

  object.marked_for_destruction?
end