Class: SnipSnip::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/snip_snip/registry.rb

Overview

A list of records that were found during the course of the last request on which we are tracking columns.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



9
10
11
# File 'lib/snip_snip/registry.rb', line 9

def initialize
  clear
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



7
8
9
# File 'lib/snip_snip/registry.rb', line 7

def records
  @records
end

Class Method Details

.instanceObject

The singleton instance of this registry.



34
35
36
# File 'lib/snip_snip/registry.rb', line 34

def instance
  @instance ||= new
end

.method_missing(method, *args, &block) ⇒ Object

Delegate all missing methods to the singleton instance.



39
40
41
42
43
# File 'lib/snip_snip/registry.rb', line 39

def method_missing(method, *args, &block)
  return super unless respond_to_missing?(method)

  instance.public_send(method, *args, &block)
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Respond to all of the missing methods on the singleton instance.

Returns:

  • (Boolean)


46
47
48
# File 'lib/snip_snip/registry.rb', line 46

def respond_to_missing?(method, include_private = false)
  instance.respond_to?(method) || super
end

Instance Method Details

#clearObject

Wipe the registry clear of found objects so that we don’t report on them twice.



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

def clear
  @records = []
end

#each_record(&block) ⇒ Object

Loop through each record that was found during the lifespan of this registry



21
22
23
24
25
# File 'lib/snip_snip/registry.rb', line 21

def each_record(&block)
  return to_enum(:each_record) unless block_given?

  records.each(&block)
end

#register(record) ⇒ Object

Add a record to this registry



28
29
30
# File 'lib/snip_snip/registry.rb', line 28

def register(record)
  records << record
end