Module: Axn::Mountable::MountingStrategies::Method
- Extended by:
- Method
- Includes:
- Base
- Included in:
- Method
- Defined in:
- lib/axn/mountable/mounting_strategies/method.rb
Defined Under Namespace
Modules: DSL
Instance Method Summary
collapse
Methods included from Base
#_should_raise_method_collision_error?, #define_namespace_methods, #key, #mount, #mount_method, #mount_to_namespace
Instance Method Details
#default_inherit_mode ⇒ Object
10
|
# File 'lib/axn/mountable/mounting_strategies/method.rb', line 10
def default_inherit_mode = :lifecycle
|
#mount_to_target(descriptor:, target:) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/axn/mountable/mounting_strategies/method.rb', line 57
def mount_to_target(descriptor:, target:)
name = descriptor.name
mount_method(target:, method_name: "#{name}!") do |**kwargs|
axn_klass = descriptor.mounted_axn_for(target: self)
exposed_fields = axn_klass.external_field_configs.map(&:field)
expose_return_as = exposed_fields.size == 1 ? exposed_fields.first : nil
result = axn_klass.call!(**kwargs)
return result if expose_return_as.nil?
result.public_send(expose_return_as)
end
end
|
#preprocess_kwargs(**kwargs) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/axn/mountable/mounting_strategies/method.rb', line 29
def preprocess_kwargs(**kwargs)
processed_kwargs = super
processed_kwargs[:expose_return_as] = processed_kwargs[:expose_return_as].presence || :value
if processed_kwargs[:exposes].present?
raise MountingError,
"Methods aren't capable of exposing multiple values (will automatically expose return value instead)"
end
if processed_kwargs[:axn_klass].present?
axn_klass = processed_kwargs[:axn_klass]
exposed_fields = axn_klass.external_field_configs.map(&:field)
if exposed_fields.size > 1
raise MountingError,
"Cannot determine expose_return_as for existing axn class with multiple exposed fields: #{exposed_fields.join(', ')}. " \
"Use a fresh block with mount_axn_method or ensure the axn class has exactly one exposed field."
end
end
processed_kwargs
end
|
#strategy_specific_kwargs ⇒ Object
27
|
# File 'lib/axn/mountable/mounting_strategies/method.rb', line 27
def strategy_specific_kwargs = super + [:expose_return_as]
|