Module: Chronicles

Defined in:
lib/chronicles.rb,
lib/chronicles/methods.rb,
lib/chronicles/updater.rb,
lib/chronicles/injector.rb

Overview

The module adds features to keep chronicles of object’s methods calls

Defined Under Namespace

Classes: Injector, Methods, Updater

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chroniclesArray<Symbol> (readonly)

Returns the array of object methods having been called

Returns:

  • (Array<Symbol>)


15
16
17
# File 'lib/chronicles.rb', line 15

def chronicles
  @chronicles ||= []
end

Instance Method Details

#start_chronicles(**options) ⇒ undefined

Starts registation of calls of the selected methods of the object

Examples:

class Test
  include Chronicles
end

test = Test.new
test.start_chronicles only: :foo
test.foo
test.bar
test.baz
test.foo
test.chronicles # => [:foo, :foo]

Parameters:

  • options (Hash)

    describes the selection of methods to include to chronicles

Options Hash (**options):

  • :public (Boolean) — default: true

    whether public methods should be looked after

  • :protected (Boolean) — default: true

    whether protected methods should be looked after

  • :private (Boolean) — default: true

    whether private methods should be looked after

  • :except (Array<#to_sym>) — default: []

    the whitelist of methods that shouldn’t be looked after

  • :only (Array<#to_sym>) — default: []

    the whitelist of methods that should be looked after

Returns:

  • (undefined)


48
49
50
# File 'lib/chronicles.rb', line 48

def start_chronicles(**options)
  Injector.new(self, "chronicles << __method__", options).run
end

#stop_chronicles(**options) ⇒ undefined

Stops registation of calls of the selected methods of the object

Examples:

class Test
  include Chronicles
end

test = Test.new
test.start_chronicles
test.foo
test.bar
test.baz
test.chronicles # => [:foo, :bar, :baz]

test.stop_chronicles except: :foo
test.foo
test.bar
test.baz
test.chronicles # => [:foo, :bar, :baz, :foo]

Parameters:

  • options (Hash)

    describes the selection of methods to include to chronicles

Options Hash (**options):

  • :public (Boolean) — default: true

    whether public methods should be looked after

  • :protected (Boolean) — default: true

    whether protected methods should be looked after

  • :private (Boolean) — default: true

    whether private methods should be looked after

  • :except (Array<#to_sym>) — default: []

    the whitelist of methods that shouldn’t be looked after

  • :only (Array<#to_sym>) — default: []

    the whitelist of methods that should be looked after

Returns:

  • (undefined)


76
77
78
# File 'lib/chronicles.rb', line 76

def stop_chronicles(**options)
  Injector.new(self, options).run
end