Sha256: a461af443506838b4f8698bd21a8b823b9c29cbaa99cdcd71de19e1e2f257a88

Contents?: true

Size: 1.3 KB

Versions: 52

Compression:

Stored size: 1.3 KB

Contents

module Dragonfly
  class Analyser < FunctionManager
    
    configurable_attr :enable_cache, true
    configurable_attr :cache_size, 100
    
    def initialize
      super
      analyser = self
      @analysis_methods = Module.new do

        define_method :analyser do
          analyser
        end
        
      end
      @analysis_method_names = []
    end
    
    attr_reader :analysis_methods, :analysis_method_names
    
    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
    
    # 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)'
    def add(name, *args, &block)
      analysis_methods.module_eval %(
        def #{name}(*args)
          analyse(:#{name}, *args)
        end
      )
      analysis_method_names << name.to_sym
      super
    end
    
    def clear_cache!
      @cache = nil
    end
    
    private
    
    def cache
      @cache ||= SimpleCache.new(cache_size)
    end
    
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
classiccms-0.5.16 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.15 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.14 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.13 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.12 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.11 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.10 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.9 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.8 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.7 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.6 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.5 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.2 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.1 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.5.0 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.4.2 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.4.1 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.4.0 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.3.9 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb
classiccms-0.3.8 vendor/bundle/gems/dragonfly-0.9.12/lib/dragonfly/analyser.rb