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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 45 def initialize(entity:, method:, observe_middleware:) @entity = entity @method = method @observe_middleware = observe_middleware ## # TODO: When middleware is NOT used yet (`::ConvenientService.raise Exceptions::NoMiddlewareIsSetToObserve.new`). # 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.
25 26 27 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 25 def entity @entity end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
31 32 33 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 31 def method @method end |
#observe_middleware ⇒ Object (readonly)
Returns the value of attribute observe_middleware.
37 38 39 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 37 def observe_middleware @observe_middleware end |
Instance Method Details
#==(other) ⇒ Boolean?
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 186 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 return false if chain != other.chain true end |
#call(*args, **kwargs, &block) ⇒ Object
Returns Can be any type.
110 111 112 113 114 115 116 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 110 def call(*args, **kwargs, &block) entity.__send__(method, *args, **kwargs, &block) rescue => exception chain[:exception] = exception raise end |
#chain_args ⇒ Array
146 147 148 149 150 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 146 def chain_args ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :args) unless chain_called? chain[:arguments].args end |
#chain_block ⇒ Proc?
166 167 168 169 170 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 166 def chain_block ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :block) unless chain_called? chain[:arguments].block end |
#chain_called? ⇒ Boolean
128 129 130 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 128 def chain_called? chain.has_key?(:called) end |
#chain_exception ⇒ StandardError?
176 177 178 179 180 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 176 def chain_exception ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :exception) unless chain_called? chain[:exception] end |
#chain_kwargs ⇒ Hash
156 157 158 159 160 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 156 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.
136 137 138 139 140 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 136 def chain_value ::ConvenientService.raise Exceptions::ChainAttributePreliminaryAccess.new(attribute: :value) unless chain_called? chain[:value] end |
#handle_after_chain_next(value, _arguments) ⇒ Object
76 77 78 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 76 def handle_after_chain_next(value, _arguments) chain[:value] = value end |
#handle_before_chain_next(arguments) ⇒ Object
67 68 69 70 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 67 def handle_before_chain_next(arguments) chain[:called] = true chain[:arguments] = arguments end |
#klass ⇒ Class
90 91 92 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 90 def klass @klass ||= Utils::Object.clamp_class(entity) end |
#observable_middleware ⇒ Class
97 98 99 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 97 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.
121 122 123 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 121 def reset! chain.clear end |
#scope ⇒ String
83 84 85 |
# File 'lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb', line 83 def scope @scope ||= Utils::Object.resolve_type(entity).to_sym end |