Sha256: ade670bc611d549497e5464111947156fd27bfce28c53bf16532cbcb113dcb33

Contents?: true

Size: 736 Bytes

Versions: 6

Compression:

Stored size: 736 Bytes

Contents

module Captcher
  class Config < OpenStruct
    def initialize
      super
      yield(self) if block_given?
    end

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

    def respond_to_missing?
      true
    end

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

    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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
captcher-0.3.1 lib/captcher/config.rb
captcher-0.3.0 lib/captcher/config.rb
captcher-0.2.1 lib/captcher/config.rb
captcher-0.2.0 lib/captcher/config.rb
captcher-0.1.1 lib/captcher/config.rb
captcher-0.1.0 lib/captcher/config.rb