Class: Praxis::Stats::Plugin

Inherits:
Plugin
  • Object
show all
Includes:
Singleton
Defined in:
lib/praxis/stats.rb

Instance Attribute Summary

Attributes inherited from Plugin

#application, #block, #config, #config_attribute

Instance Method Summary collapse

Methods inherited from Plugin

#after, #before, #load_config!, #options

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



23
24
25
# File 'lib/praxis/stats.rb', line 23

def initialize
  @options = {config_file: 'config/stats.yml'}
end

Instance Method Details

#config_keyObject



27
28
29
# File 'lib/praxis/stats.rb', line 27

def config_key
  :stats # 'praxis.stats'
end

#load_type(hash) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/praxis/stats.rb', line 49

def load_type(hash)
  type = hash[:type].constantize
  args = hash[:args]
  args_hash = case args
  when Attributor::Hash
    args.contents.symbolize_keys
  when Hash
    args.symbolize_keys
  when nil
    {}
  else
    raise "unknown args type: #{args.class.name}"
  end
  
  if args_hash.any?        
    type.new(**args_hash)
  else
    type.new
  end

end

#prepare_config!(node) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/praxis/stats.rb', line 31

def prepare_config!(node)
  node.attributes do
    attribute :collector, Hash, default: {type: 'Harness::FakeCollector'} do
      key :type, String, required: true
      key :args, Hash
    end
    attribute :queue, Hash, default: {type: 'Harness::AsyncQueue' } do
      key :type, String, required: true
      key :args, Hash
    end
  end
end

#setup!Object



44
45
46
47
# File 'lib/praxis/stats.rb', line 44

def setup!
  Harness.config.collector = load_type(config.collector)
  Harness.config.queue = load_type(config.queue)
end