Class: Rabarber::Inputs::Context

Inherits:
Base
  • Object
show all
Defined in:
lib/rabarber/inputs/context.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #process

Constructor Details

This class inherits a constructor from Rabarber::Inputs::Base

Instance Method Details

#resolveObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rabarber/inputs/context.rb', line 6

def resolve
  case context = process
  when nil
    { context_type: nil, context_id: nil }
  when Class
    { context_type: context.to_s, context_id: nil }
  when ActiveRecord::Base
    raise_error unless context.persisted?
    { context_type: context.class.to_s, context_id: context.public_send(context.class.primary_key) }
  else
    context
  end
end