Class: Stratagem::Instrumentation::Models::InstanceAnnotations
- Includes:
- Mocking
- Defined in:
- lib/stratagem/instrumentation/models/annotations.rb
Instance Method Summary collapse
-
#initialize(object) ⇒ InstanceAnnotations
constructor
A new instance of InstanceAnnotations.
- #method_missing(method, *args, &block) ⇒ Object
-
#related_objects(collection_size_limit = 5000) ⇒ Object
objects that are related to this object.
- #traverse_objects(collection_size_limit, collection = [], class_chain = []) ⇒ Object
Methods included from Mocking
#mock_attributes, #read_mock_attribute, #used_in_mock_relation, #used_in_mock_relation?, #write_mock_attribute
Constructor Details
#initialize(object) ⇒ InstanceAnnotations
Returns a new instance of InstanceAnnotations.
8 9 10 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 8 def initialize(object) @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
12 13 14 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 12 def method_missing(method, *args, &block) @object.class.stratagem.send(method, *args, &block) end |
Instance Method Details
#related_objects(collection_size_limit = 5000) ⇒ Object
objects that are related to this object
17 18 19 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 17 def (collection_size_limit=5000) traverse_objects(collection_size_limit) end |
#traverse_objects(collection_size_limit, collection = [], class_chain = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 21 def traverse_objects(collection_size_limit, collection=[], class_chain=[]) return if collection.size >= collection_size_limit unless collection.include?(@object) collection << @object relations(:has_many).each do |relation| puts "relation #{relation.name} - #{collection.size} - #{relation.klass}" if (relation.klass && !class_chain.include?(relation.klass)) class_chain << relation.klass begin = @object.send(relation.name) if (.kind_of?(Array)) .each {|r| r.stratagem.traverse_objects(collection_size_limit, collection, class_chain) } elsif (!.nil?) .stratagem.traverse_objects(collection_size_limit, collection, class_chain) end rescue Stratagem.logger.error($!) end end end end collection end |