Class: Dragonfly::Analyser
- Inherits:
-
FunctionManager
- Object
- FunctionManager
- Dragonfly::Analyser
- Defined in:
- lib/dragonfly/analyser.rb
Instance Attribute Summary collapse
-
#analysis_method_names ⇒ Object
readonly
Returns the value of attribute analysis_method_names.
-
#analysis_methods ⇒ Object
readonly
Returns the value of attribute analysis_methods.
Attributes inherited from FunctionManager
Instance Method Summary collapse
-
#add(name, *args, &block) ⇒ Object
Each time a function is registered with the analyser, add a method to the analysis_methods module.
- #analyse(temp_object, method, *args) ⇒ Object
- #clear_cache! ⇒ Object
-
#initialize ⇒ Analyser
constructor
A new instance of Analyser.
Methods inherited from FunctionManager
#call_last, #get_registered, #inspect, #register
Constructor Details
#initialize ⇒ Analyser
Returns a new instance of Analyser.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dragonfly/analyser.rb', line 8 def initialize super analyser = self @analysis_methods = Module.new do define_method :analyser do analyser end end @analysis_method_names = [] end |
Instance Attribute Details
#analysis_method_names ⇒ Object (readonly)
Returns the value of attribute analysis_method_names
21 22 23 |
# File 'lib/dragonfly/analyser.rb', line 21 def analysis_method_names @analysis_method_names end |
#analysis_methods ⇒ Object (readonly)
Returns the value of attribute analysis_methods
21 22 23 |
# File 'lib/dragonfly/analyser.rb', line 21 def analysis_methods @analysis_methods end |
Instance Method Details
#add(name, *args, &block) ⇒ Object
Each time a function is registered with the analyser, add a method to the analysis_methods module. Expects the object that is extended to define ‘analyse(method, *args)’
38 39 40 41 42 43 44 45 46 |
# File 'lib/dragonfly/analyser.rb', line 38 def add(name, *args, &block) analysis_methods.module_eval %( def #{name}(*args) analyse(:#{name}, *args) end ) analysis_method_names << name.to_sym super end |
#analyse(temp_object, method, *args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dragonfly/analyser.rb', line 23 def analyse(temp_object, method, *args) if enable_cache key = [temp_object.object_id, method, *args] cache[key] ||= call_last(method, temp_object, *args) else call_last(method, temp_object, *args) end rescue NotDefined, UnableToHandle => e log.warn(e.) nil end |
#clear_cache! ⇒ Object
48 49 50 |
# File 'lib/dragonfly/analyser.rb', line 48 def clear_cache! @cache = nil end |