Module: Torque::PostgreSQL::Collector

Defined in:
lib/torque/postgresql/collector.rb

Class Method Summary collapse

Class Method Details

.new(*args) ⇒ Object

This classe helps to collect data in different ways. Used to configure auxiliary statements



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/torque/postgresql/collector.rb', line 9

def self.new(*args)
  klass = Class.new

  args.flatten!
  args.compact!

  klass.module_eval do
    args.each do |attribute|
      define_method attribute do |*args|
        if args.empty?
          instance_variable_get("@#{attribute}")
        elsif args.size > 1
          instance_variable_set("@#{attribute}", args)
        else
          instance_variable_set("@#{attribute}", args.first)
        end
      end
      alias_method "#{attribute}=", attribute
    end
  end

  klass
end