Module: BindingDumper::MagicObjects
- Defined in:
- lib/binding_dumper/magic_objects.rb
Overview
Module responsible for storing and retrieving ‘magical’ objects
Object is 'magical' if it's the same for every Ruby process
Examples of ‘magical’ objects:
Rails.application
Rails.env
Rails.application.config
To register an object, run: After marking an object as ‘magical’ it (and all embedded objects)
will be added to the object pool of 'magical' objects
Class Method Summary collapse
-
.flush! ⇒ Object
Flushes existing information about ‘magical’ objects.
-
.get_magic(object) ⇒ String
Returns the way to get a ‘magical’ object.
-
.magic?(object) ⇒ true, false
Returns true if passed
objectis ‘magical’. -
.magic_tree_from(object, object_path, result = {}) ⇒ Hash
Builds a tree of objects inside of passed
object. -
.pool ⇒ Hash
Returns Hash containing all magical objects.
-
.register(object, object_path = object.name) ⇒ Object
Registers passed object as ‘magical’.
Class Method Details
.flush! ⇒ Object
Flushes existing information about ‘magical’ objects
95 96 97 |
# File 'lib/binding_dumper/magic_objects.rb', line 95 def self.flush! @pool = {} end |
.get_magic(object) ⇒ String
Returns the way to get a ‘magical’ object
89 90 91 |
# File 'lib/binding_dumper/magic_objects.rb', line 89 def self.get_magic(object) pool[object.object_id] end |
.magic?(object) ⇒ true, false
Returns true if passed object is ‘magical’
79 80 81 |
# File 'lib/binding_dumper/magic_objects.rb', line 79 def self.magic?(object) pool.has_key?(object.object_id) end |
.magic_tree_from(object, object_path, result = {}) ⇒ Hash
Builds a tree of objects inside of passed object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/binding_dumper/magic_objects.rb', line 42 def self.magic_tree_from(object, object_path, result = {}) return if result[object.object_id] result[object.object_id] = object_path object.instance_variables.each do |ivar_name| path = "#{object_path}.instance_variable_get(:#{ivar_name})" ivar = object.instance_variable_get(ivar_name) magic_tree_from(ivar, path, result) end result end |
.pool ⇒ Hash
Returns Hash containing all magical objects
71 72 73 |
# File 'lib/binding_dumper/magic_objects.rb', line 71 def self.pool @pool ||= {} end |
.register(object, object_path = object.name) ⇒ Object
Registers passed object as ‘magical’
61 62 63 64 65 |
# File 'lib/binding_dumper/magic_objects.rb', line 61 def self.register(object, object_path = object.name) tree = magic_tree_from(object, object_path) pool.merge!(tree) true end |