Class: Realm::ActionHandler

Inherits:
Object
  • Object
show all
Extended by:
Mixins::ContextInjection::ClassMethods
Includes:
Mixins::AggregateMember, Mixins::RepositoryHelper
Defined in:
lib/realm/action_handler.rb,
lib/realm/action_handler/result.rb

Direct Known Subclasses

CommandHandler, QueryHandler

Defined Under Namespace

Classes: Result

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::ContextInjection::ClassMethods

inject

Methods included from Mixins::RepositoryHelper

included

Methods included from Mixins::AggregateMember

#aggregate, included

Constructor Details

#initialize(runtime: nil) ⇒ ActionHandler

Returns a new instance of ActionHandler.



56
57
58
# File 'lib/realm/action_handler.rb', line 56

def initialize(runtime: nil)
  @runtime = runtime
end

Class Attribute Details

.contractsObject (readonly)

Returns the value of attribute contracts.



18
19
20
# File 'lib/realm/action_handler.rb', line 18

def contracts
  @contracts
end

Class Method Details

.call(action: :handle, params: {}, runtime: nil) ⇒ Object



20
21
22
# File 'lib/realm/action_handler.rb', line 20

def call(action: :handle, params: {}, runtime: nil)
  new(runtime: runtime).(action: action, params: params)
end

Instance Method Details

#call(action: :handle, params: {}) ⇒ Object

Raises:



60
61
62
63
64
65
66
# File 'lib/realm/action_handler.rb', line 60

def call(action: :handle, params: {})
  # TODO: check permissions
  raise CannotHandleAction.new(self, action) unless respond_to?(action)

  safe_params = validate(action, params.to_h)
  send(action, **safe_params)
end