Sha256: 56ee7ac59faa60a8dba384eef3d3e166a849d9d064679f4ed79cfdae8f729226

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Flipper
  module Toggles
    class Boolean < Toggle
      TruthMap = {
        true    => true,
        'true'  => true,
        'TRUE'  => true,
        'True'  => true,
        't'     => true,
        'T'     => true,
        '1'     => true,
        'on'    => true,
        'ON'    => true,
        1       => true,
        1.0     => true,
        false   => false,
        'false' => false,
        'FALSE' => false,
        'False' => false,
        'f'     => false,
        'F'     => false,
        '0'     => false,
        'off'   => false,
        'OFF'   => false,
        0       => false,
        0.0     => false,
        nil     => false,
      }

      def enable(thing)
        super
        adapter.write adapter_key, thing.value
        true
      end

      def disable(thing)
        super
        feature.gates.each do |gate|
          gate.adapter.delete gate.adapter_key
        end
        true
      end

      def value
        value = adapter.read(adapter_key)
        !!TruthMap[value]
      end

      def enabled?
        value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flipper-0.4.0 lib/flipper/toggles/boolean.rb