Class: Axn::Core::ContextFacade

Inherits:
Object
  • Object
show all
Defined in:
lib/axn/core/context/facade.rb

Direct Known Subclasses

InternalContext, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:, context:, declared_fields:, implicitly_allowed_fields: nil) ⇒ ContextFacade

Returns a new instance of ContextFacade.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/axn/core/context/facade.rb', line 8

def initialize(action:, context:, declared_fields:, implicitly_allowed_fields: nil)
  if self.class.name == "Axn::Core::ContextFacade" # rubocop:disable Style/ClassEqualityComparison
    raise "Axn::Core::ContextFacade is an abstract class and should not be instantiated directly"
  end

  @context = context
  @action = action
  @declared_fields = declared_fields

  (@declared_fields + Array(implicitly_allowed_fields)).each do |field|
    _define_reader_for(field)
  end
end

Instance Attribute Details

#declared_fieldsObject (readonly)

Returns the value of attribute declared_fields.



22
23
24
# File 'lib/axn/core/context/facade.rb', line 22

def declared_fields
  @declared_fields
end

Instance Method Details

#fail!Object



26
27
28
# File 'lib/axn/core/context/facade.rb', line 26

def fail!(...)
  raise Axn::ContractViolation::MethodNotAllowed, "Call fail! directly rather than on the context"
end

#inspectObject



24
# File 'lib/axn/core/context/facade.rb', line 24

def inspect = ContextFacadeInspector.new(facade: self, action:, context:).call