Class: Dragonfly::Analyser
- Inherits:
-
FunctionManager
- Object
- FunctionManager
- Dragonfly::Analyser
- Defined in:
- lib/dragonfly/analyser.rb
Instance Attribute Summary (collapse)
-
- (Object) analysis_method_names
readonly
Returns the value of attribute analysis_method_names.
-
- (Object) analysis_methods
readonly
Returns the value of attribute analysis_methods.
Attributes inherited from FunctionManager
Attributes included from Loggable
Configuration Summary
Configurable attributes
Configurable attributes for an object in generalobject
can be configured either by using something like
object.configure do |c| c.some_configurable_attribute = "some value" c.some_other_configurable_attribute = 42 ... endor
object.some_configurable_attribute = "some value"
Configurable attributes for instances of Dragonfly::Analyser
-
enable_cache
- defaulttrue
-
cache_size
- default100
Instance Method Summary (collapse)
-
- (Object) add(name, *args, &block)
Each time a function is registered with the analyser, add a method to the analysis_methods module.
- - (Object) analyse(temp_object, method, *args)
- - (Object) clear_cache!
-
- (Analyser) initialize
constructor
A new instance of Analyser.
Methods inherited from FunctionManager
#call_last, #get_registered, #inspect, #register
Methods included from Configurable
Methods included from Loggable
Constructor Details
- (Analyser) initialize
Returns a new instance of Analyser
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dragonfly/analyser.rb', line 7 def initialize super analyser = self @analysis_methods = Module.new do define_method :analyser do analyser end end @analysis_method_names = [] end |
Instance Attribute Details
- (Object) analysis_method_names (readonly)
Returns the value of attribute analysis_method_names
20 21 22 |
# File 'lib/dragonfly/analyser.rb', line 20 def analysis_method_names @analysis_method_names end |
- (Object) analysis_methods (readonly)
Returns the value of attribute analysis_methods
20 21 22 |
# File 'lib/dragonfly/analyser.rb', line 20 def analysis_methods @analysis_methods end |
Instance Method Details
- (Object) add(name, *args, &block)
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)'
37 38 39 40 41 42 43 44 45 |
# File 'lib/dragonfly/analyser.rb', line 37 def add(name, *args, &block) analysis_methods.module_eval %( def #{name}(*args) analyse(:#{name}, *args) end ) analysis_method_names << name.to_sym super end |
- (Object) analyse(temp_object, method, *args)
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dragonfly/analyser.rb', line 22 def analyse(temp_object, method, *args) if enable_cache key = [temp_object.unique_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 |
- (Object) clear_cache!
47 48 49 |
# File 'lib/dragonfly/analyser.rb', line 47 def clear_cache! @cache = nil end |