Class: Axn::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.



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

def initialize(action:, context:, declared_fields:, implicitly_allowed_fields: nil)
  if self.class.name == "Axn::ContextFacade" # rubocop:disable Style/ClassEqualityComparison
    raise "Axn::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|
    if _model_fields.key?(field)
      _define_model_field_method(field, _model_fields[field])
    else
      singleton_class.define_method(field) do
        _context_data_source[field]
      end
    end
  end
end

Instance Attribute Details

#declared_fieldsObject (readonly)

Returns the value of attribute declared_fields.



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

def declared_fields
  @declared_fields
end

Instance Method Details

#fail!Object



31
32
33
# File 'lib/axn/core/context/facade.rb', line 31

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

#inspectObject



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

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