Class: Fluent::Config::Section

Inherits:
BasicObject
Defined in:
lib/fluent/config/section.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, config_element = nil) ⇒ Section

Returns a new instance of Section.



29
30
31
32
33
# File 'lib/fluent/config/section.rb', line 29

def initialize(params = {}, config_element = nil)
  @klass = 'Fluent::Config::Section'
  @params = params
  @corresponding_config_element = config_element
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/fluent/config/section.rb', line 103

def method_missing(name, *args)
  if @params.has_key?(name)
    @params[name]
  else
    ::Kernel.raise ::NoMethodError, "undefined method `#{name}' for #{self.inspect}"
  end
end

Class Method Details

.nameObject



25
26
27
# File 'lib/fluent/config/section.rb', line 25

def self.name
  'Fluent::Config::Section'
end

Instance Method Details

#+(other) ⇒ Object



65
66
67
# File 'lib/fluent/config/section.rb', line 65

def +(other)
  Section.new(self.to_h.merge(other.to_h))
end

#[](key) ⇒ Object



78
79
80
# File 'lib/fluent/config/section.rb', line 78

def [](key)
  @params[key.to_sym]
end

#[]=(key, value) ⇒ Object



82
83
84
# File 'lib/fluent/config/section.rb', line 82

def []=(key, value)
  @params[key.to_sym] = value
end

#classObject



41
42
43
# File 'lib/fluent/config/section.rb', line 41

def class
  Section
end

#corresponding_config_elementObject



37
38
39
# File 'lib/fluent/config/section.rb', line 37

def corresponding_config_element
  @corresponding_config_element
end

#dupObject



61
62
63
# File 'lib/fluent/config/section.rb', line 61

def dup
  Section.new(@params.dup, @corresponding_config_element.dup)
end

#inspectObject



49
50
51
# File 'lib/fluent/config/section.rb', line 49

def inspect
  "<Fluent::Config::Section #{@params.to_json}>"
end

#instance_of?(mod) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fluent/config/section.rb', line 69

def instance_of?(mod)
  @klass == mod.name
end

#kind_of?(mod) ⇒ Boolean Also known as: is_a?

Returns:

  • (Boolean)


73
74
75
# File 'lib/fluent/config/section.rb', line 73

def kind_of?(mod)
  @klass == mod.name || BasicObject == mod
end

#nil?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/fluent/config/section.rb', line 53

def nil?
  false
end

#respond_to?(symbol, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fluent/config/section.rb', line 86

def respond_to?(symbol, include_all=false)
  case symbol
  when :inspect, :nil?, :to_h, :+, :instance_of?, :kind_of?, :[], :respond_to?, :respond_to_missing?
    true
  when :!, :!= , :==, :equal?, :instance_eval, :instance_exec
    true
  when :method_missing, :singleton_method_added, :singleton_method_removed, :singleton_method_undefined
    include_all
  else
    false
  end
end

#respond_to_missing?(symbol, include_private) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/fluent/config/section.rb', line 99

def respond_to_missing?(symbol, include_private)
  @params.has_key?(symbol)
end

#to_hObject



57
58
59
# File 'lib/fluent/config/section.rb', line 57

def to_h
  @params
end

#to_sObject



45
46
47
# File 'lib/fluent/config/section.rb', line 45

def to_s
  inspect
end