Class: Captcher::Config

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/captcher/config.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



3
4
5
6
# File 'lib/captcher/config.rb', line 3

def initialize
  super
  yield(self) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/captcher/config.rb', line 16

def method_missing(name, *args)
  if block_given?
    branch = self.class.new
    yield(branch)
    args = [branch]
  end
  name = to_writer(name, args)
  super
end

Instance Method Details

#merge(other) ⇒ Object



8
9
10
# File 'lib/captcher/config.rb', line 8

def merge(other)
  to_h.merge(other.to_h)
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/captcher/config.rb', line 12

def respond_to_missing?
  true
end

#to_hObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/captcher/config.rb', line 26

def to_h
  attributes = super
  attributes.map do |key, value|
    if value.class == self.class
      [key, value.to_h]
    else
      [key, value]
    end
  end.to_h
end

#to_writer(name, args) ⇒ Object



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

def to_writer(name, args)
  args && (name !~ /=$/) ? "#{name}=" : name
end