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

Configuration Summary

Configurable attributes

Configurable attributes for an object in general object can be configured either by using something like
  object.configure do |c|
    c.some_configurable_attribute = "some value"
    c.some_other_configurable_attribute = 42
    ...
  end
or
  object.some_configurable_attribute = "some value"

Configurable attributes for instances of Dragonfly::Analyser

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

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

- (Object) clear_cache!



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

def clear_cache!
  @cache = nil
end