Class: InertRecorder

Inherits:
Object show all
Defined in:
lib/y_support/misc/inert_recorder.rb

Overview

Inert recorder is similar to a null object in the sense, that in response to almost all messages it returns self. But in addition, it records received messages along with their arguments and blocks (if given). Recoded messages are available via #recorded_messages reader, aliased #ρ (small Greek rho). Inert recorder does not require any arguments for initalization, but if they are supplied, they are silently recoded into @init_args (for arguments) and readers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ InertRecorder

No arguments are required for initialization, but if they are supplied, they are silently recorded into @init_args (for argument array) and @init_block (for block, if given) instance variables, exposed via standard readers.



22
23
24
25
26
# File 'lib/y_support/misc/inert_recorder.rb', line 22

def initialize *args, &block
  @init_args = args
  @init_block = block
  @recorded_messages = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(ß, *args, &block) ⇒ Object

:nodoc:



40
41
42
43
# File 'lib/y_support/misc/inert_recorder.rb', line 40

def method_missing ß, *args, &block      # :nodoc:
  @recorded_messages << [ ß, args, block ]
  return self
end

Instance Attribute Details

#init_argsObject (readonly)

Returns the value of attribute init_args.



15
16
17
# File 'lib/y_support/misc/inert_recorder.rb', line 15

def init_args
  @init_args
end

#init_blockObject (readonly)

Returns the value of attribute init_block.



15
16
17
# File 'lib/y_support/misc/inert_recorder.rb', line 15

def init_block
  @init_block
end

#recorded_messagesObject (readonly) Also known as: ρ

Returns the value of attribute recorded_messages.



15
16
17
# File 'lib/y_support/misc/inert_recorder.rb', line 15

def recorded_messages
  @recorded_messages
end

Instance Method Details

#blank?Boolean

Always false.

Returns:

  • (Boolean)


34
# File 'lib/y_support/misc/inert_recorder.rb', line 34

def blank?; false end

#present?Boolean

Always true.

Returns:

  • (Boolean)


30
# File 'lib/y_support/misc/inert_recorder.rb', line 30

def present?; true end

#respond_to?(ß, *args, &block) ⇒ Boolean

Always true.

Returns:

  • (Boolean)


38
# File 'lib/y_support/misc/inert_recorder.rb', line 38

def respond_to? ß, *args, &block; true end