Sha256: 7f23e7a0ab545941cb09d5401d9d6a14921826eab54f511fcbf665ab147e5f9c

Contents?: true

Size: 634 Bytes

Versions: 12

Compression:

Stored size: 634 Bytes

Contents

# frozen_string_literal: true

require_relative 'base'

module RubyVault
  module Options
    module Values
      class Boolean < Base
        def resolve
          return nil if @value.nil?
          return @value if a_boolean?(@value)
          return true if true_as_string?(@value)

          false
        end

        def render
          resolve&.to_s
        end

        private

        def a_boolean?(value)
          value.is_a?(TrueClass) || value.is_a?(FalseClass)
        end

        def true_as_string?(value)
          value.respond_to?(:downcase) && value.downcase == 'true'
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby_vault-0.3.0.pre.2 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.3.0.pre.1 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0.pre.6 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0.pre.5 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0.pre.4 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0.pre.3 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0.pre.2 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.2.0.pre.1 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.1.0 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.1.0.pre.18 lib/ruby_vault/options/values/boolean.rb
ruby_vault-0.1.0.pre.17 lib/ruby_vault/options/values/boolean.rb