Class: ILove::Tracing::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ilove/tracing.rb

Class Method Summary collapse

Class Method Details

.config_param(symbol, default_value = nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ilove/tracing.rb', line 7

def self.config_param(symbol, default_value = nil, &block)
  raise 'wrong args' if !default_value.nil? && block_given?

  if block_given?
    class_variable_set("@@#{symbol}_default", block)
    class_eval("      def \#{symbol}_default\n        instance_eval &@@\#{symbol}_default\n      end\n    RUBY\n  else\n    class_variable_set(\"@@\#{symbol}_default\", default_value)\n    class_eval(<<~RUBY, __FILE__, __LINE__ + 1)\n      def \#{symbol}_default\n        @@\#{symbol}_default\n      end\n    RUBY\n  end\n\n  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)\n    def \#{symbol}\n      @\#{symbol} ||= \#{symbol}_default\n    end\n  RUBY\n\n  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)\n    def \#{symbol}?\n      \#{symbol}\n    end\n\n    def \#{symbol}=(value)\n      @\#{symbol} = value\n    end\n  RUBY\nend\n", __FILE__, __LINE__ + 1)