Class: ConvenientService::RSpec::Helpers::Classes::WrapMethod::Entities::WrappedMethod
- Inherits:
-
Object
- Object
- ConvenientService::RSpec::Helpers::Classes::WrapMethod::Entities::WrappedMethod
- Defined in:
- lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#observe_middleware ⇒ Object
readonly
Returns the value of attribute observe_middleware.
Instance Method Summary collapse
- #==(other) ⇒ Boolean?
-
#call(*args, **kwargs, &block) ⇒ Object
Can be any type.
- #chain_args ⇒ Array
- #chain_block ⇒ Proc?
- #chain_called? ⇒ Boolean
- #chain_exception ⇒ StandardError?
- #chain_kwargs ⇒ Hash
-
#chain_value ⇒ Object
Can be any type.
- #handle_after_chain_next(value, _arguments) ⇒ Object
- #handle_before_chain_next(arguments) ⇒ Object
- #initialize(entity:, method:, observe_middleware:) ⇒ void constructor
- #klass ⇒ Class
- #observable_middleware ⇒ Class
- #reset! ⇒ void
- #scope ⇒ String
Constructor Details
#initialize(entity:, method:, observe_middleware:) ⇒ void
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 40 def initialize(entity:, method:, observe_middleware:) @entity = entity @method = method @observe_middleware = observe_middleware ## # TODO: When middleware is NOT used yet. # observable_middleware.middleware_events[:before_chain_next].add_observer(self) observable_middleware.middleware_events[:after_chain_next].add_observer(self) ## # TODO: Consider `ObjectSpace.define_finalizer`? Is it really needed? # # observable_middleware.middleware_events[:before_chain_next].delete_observer(self) # observable_middleware.middleware_events[:after_chain_next].delete_observer(self) end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
20 21 22 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 20 def entity @entity end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
26 27 28 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 26 def method @method end |
#observe_middleware ⇒ Object (readonly)
Returns the value of attribute observe_middleware.
32 33 34 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 32 def observe_middleware @observe_middleware end |
Instance Method Details
#==(other) ⇒ Boolean?
184 185 186 187 188 189 190 191 192 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 184 def ==(other) return unless other.instance_of?(self.class) return false if entity != other.entity return false if method != other.method return false if observe_middleware != other.observe_middleware true end |
#call(*args, **kwargs, &block) ⇒ Object
Returns Can be any type.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 102 def call(*args, **kwargs, &block) entity.__send__(method, *args, **kwargs, &block) rescue => exception @chain_exception = exception ## # NOTE: `raise` with no args inside `rescue` reraises rescued exception. # raise end |
#chain_args ⇒ Array
144 145 146 147 148 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 144 def chain_args ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :args) unless chain_called? @chain_arguments.args end |
#chain_block ⇒ Proc?
164 165 166 167 168 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 164 def chain_block ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :block) unless chain_called? @chain_arguments.block end |
#chain_called? ⇒ Boolean
126 127 128 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 126 def chain_called? Utils.to_bool(defined? @chain_called) end |
#chain_exception ⇒ StandardError?
174 175 176 177 178 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 174 def chain_exception ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :exception) unless chain_called? @chain_exception end |
#chain_kwargs ⇒ Hash
154 155 156 157 158 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 154 def chain_kwargs ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :kwargs) unless chain_called? @chain_arguments.kwargs end |
#chain_value ⇒ Object
Returns Can be any type.
134 135 136 137 138 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 134 def chain_value ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :value) unless chain_called? @chain_value end |
#handle_after_chain_next(value, _arguments) ⇒ Object
71 72 73 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 71 def handle_after_chain_next(value, _arguments) @chain_value = value end |
#handle_before_chain_next(arguments) ⇒ Object
62 63 64 65 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 62 def handle_before_chain_next(arguments) @chain_called = true @chain_arguments = arguments end |
#klass ⇒ Class
85 86 87 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 85 def klass @klass ||= Utils::Object.clamp_class(entity) end |
#observable_middleware ⇒ Class
92 93 94 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 92 def observable_middleware @observable_middleware ||= klass.middlewares(method, scope: scope).to_a.find { |other| other == observe_middleware.observable } end |
#reset! ⇒ void
This method returns an undefined value.
116 117 118 119 120 121 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 116 def reset! remove_instance_variable(:@chain_called) if defined? @chain_called remove_instance_variable(:@chain_value) if defined? @chain_value remove_instance_variable(:@chain_arguments) if defined? @chain_arguments remove_instance_variable(:@chain_exception) if defined? @chain_exception end |
#scope ⇒ String
78 79 80 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 78 def scope @scope ||= Utils::Object.resolve_type(entity).to_sym end |