module ActiveSpy::Rails::Spy::ClassMethods
Class methods to be defined in classes that includes {ActiveSpy::Spy}
Public Instance Methods
dynamically_define_method_or_call_block(abstract_name, method_name)
click to toggle source
Defines a method called method_name
that will call a method called method_value
if a symbol is provided. If a block is provided instead, it will be returned.
# File lib/active_spy/rails/spy.rb, line 36 def dynamically_define_method_or_call_block(abstract_name, method_name) return unless method_name if abstract_name == method_name attr_accessor method_name else define_method method_name do send(:instance_variable_get, "@#{abstract_name}") end define_method "#{method_name}=" do |new_value| send(:instance_variable_set, "@#{abstract_name}", new_value) end end end
inject_payload_for_method()
click to toggle source
Helper to inject the method +payload_for(method)+ in the model with the default behavior: all attributes are sent in all actions.
# File lib/active_spy/rails/spy.rb, line 62 def inject_payload_for_method define_method :payload_for do |_method| { self.class.name.downcase.to_sym => attributes } end end
model_actor(actor_name = nil)
click to toggle source
Class method to define the actor of the model.
# File lib/active_spy/rails/spy.rb, line 28 def model_actor(actor_name = nil) dynamically_define_method_or_call_block(:actor, actor_name) end
model_realm(realm_name = nil)
click to toggle source
Class method to define the realm of the model.
# File lib/active_spy/rails/spy.rb, line 22 def model_realm(realm_name = nil) dynamically_define_method_or_call_block(:realm, realm_name) end
watch_model_changes()
click to toggle source
Helper to use on Rails
app and watch for model creation, update and destruction.
# File lib/active_spy/rails/spy.rb, line 53 def watch_model_changes watch_method :save, :destroy inject_payload_for_method end