Sha256: 1e0668ad46f94100e087ee54771b17d52f1bdf10dc7da910015e51c94d8bb90c

Contents?: true

Size: 836 Bytes

Versions: 14

Compression:

Stored size: 836 Bytes

Contents

# frozen_string_literal: true

require 'dot_hash'

module PUNK
  class Settings < DotHash::Settings
    alias key? has_key?

    delegate :inspect, to: :_inspect_hash

    def method_missing(key, *args, &block)
      match = /^(.*)([!?])$/.match(key)
      if match && key?(match[1]) && !key?(key)
        value = execute(match[1], *args, &block)
        case match[2]
        when '?'
          return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
        when '!'
          raise InternalServerError, "Value is nil: #{key}" if value.nil?
          return value
        end
      end
      super
    end

    def respond_to_missing?(key, *args)
      match = /^(.*)([!?])$/.match(key)
      key = match[1] if match && !key?(key)
      super
    end

    private

    def _inspect_hash
      to_h.inspect
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
punk-0.3.6 lib/punk/core/settings.rb
punk-0.3.5 lib/punk/core/settings.rb
punk-0.3.4 lib/punk/core/settings.rb
punk-0.3.3 lib/punk/core/settings.rb
punk-0.3.2 lib/punk/core/settings.rb
punk-0.3.1 lib/punk/core/settings.rb
punk-0.2.0 lib/punk/core/settings.rb
punk-0.1.4 lib/punk/core/settings.rb
punk-0.1.3 lib/punk/core/settings.rb
punk-0.1.2 lib/punk/core/settings.rb
punk-0.1.0 lib/punk/core/settings.rb
punk-0.0.3 lib/punk/core/settings.rb
punk-0.0.2 lib/punk/core/settings.rb
punk-0.0.1 lib/punk/core/settings.rb