Sha256: 410de29d6d23cb07a90b946884cc6dccce0d822d45cb5aad938450c38e9325d8

Contents?: true

Size: 596 Bytes

Versions: 9

Compression:

Stored size: 596 Bytes

Contents

module Nenv
  class Environment
    class Loader
      def initialize(meth)
        @bool = meth.to_s.end_with?('?')
      end

      def load(raw_value, &callback)
        return callback.call(raw_value) if callback
        @bool ? _to_bool(raw_value) : raw_value
      end

      private

      def _to_bool(raw_value)
        case raw_value
        when nil
          nil
        when ''
          fail ArgumentError, "Can't convert empty string into Bool"
        when '0', 'false', 'n', 'no', 'NO', 'FALSE'
          false
        else
          true
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/nenv-0.2.0/lib/nenv/environment/loader.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/nenv-0.2.0/lib/nenv/environment/loader.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/nenv-0.2.0/lib/nenv/environment/loader.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/nenv-0.2.0/lib/nenv/environment/loader.rb
geminfo-0.1.0 path/gems/nenv-0.2.0/lib/nenv/environment/loader.rb
nenv-0.2.0 lib/nenv/environment/loader.rb
nenv-0.1.1 lib/nenv/environment/loader.rb
nenv-0.1.0 lib/nenv/environment/loader.rb
nenv-0.0.3 lib/nenv/environment/loader.rb