Class: Dragonfly::Analyser

Inherits:
FunctionManager show all
Defined in:
lib/dragonfly/analyser.rb

Instance Attribute Summary collapse

Attributes inherited from FunctionManager

#functions, #objects

Attributes included from Loggable

#log_object

Instance Method Summary collapse

Methods inherited from FunctionManager

#call_last, #get_registered, #inspect, #register

Methods included from Configurable

included

Methods included from Loggable

#log, #log=, #use_same_log_as

Constructor Details

#initializeAnalyser

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

#analysis_method_namesObject (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

#analysis_methodsObject (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

#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)'


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

#analyse(temp_object, method, *args) ⇒ Object


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.message)
  nil
end

#clear_cache!Object


47
48
49
# File 'lib/dragonfly/analyser.rb', line 47

def clear_cache!
  @cache = nil
end