Class: Castle::Commands::Impersonate

Inherits:
Object
  • Object
show all
Defined in:
lib/castle/commands/impersonate.rb

Overview

builder for impersonate command

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Impersonate

Returns a new instance of Impersonate.



7
8
9
# File 'lib/castle/commands/impersonate.rb', line 7

def initialize(context)
  @context = context
end

Instance Method Details

#build(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/castle/commands/impersonate.rb', line 11

def build(options = {})
  Castle::Validators::Present.call(options, i[user_id])
  context = Castle::Context::Merger.call(@context, options[:context])
  context = Castle::Context::Sanitizer.call(context)

  Castle::Validators::Present.call(context, i[user_agent ip])

  Castle::Command.new(
    'impersonate',
    options.merge(context: context, sent_at: Castle::Utils::Timestamp.call),
    options[:reset] ? :delete : :post
  )
end