Sha256: 9c7ee7843474ff8c11c6dc58f62a343367f2e8b96d2ecd92447f07881ed2f072

Contents?: true

Size: 860 Bytes

Versions: 13

Compression:

Stored size: 860 Bytes

Contents

module Toy
  module Extensions
    module Boolean
      Mapping = {
        true    => true, 
        'true'  => true, 
        'TRUE'  => true, 
        'True'  => true, 
        't'     => true, 
        'T'     => true, 
        '1'     => true, 
        1       => true, 
        1.0     => true,
        false   => false, 
        'false' => false, 
        'FALSE' => false, 
        'False' => false, 
        'f'     => false, 
        'F'     => false, 
        '0'     => false, 
        0       => false, 
        0.0     => false, 
        nil     => nil
      }

      def to_store(value, *)
        if value.is_a?(Boolean)
          value
        else
          Mapping[value]
        end
      end

      def from_store(value, *)
        value.nil? ? nil : !!value
      end
    end
  end
end

class Boolean
  extend Toy::Extensions::Boolean
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
toystore-0.8.3 lib/toy/extensions/boolean.rb
toystore-0.8.2 lib/toy/extensions/boolean.rb
toystore-0.8.1 lib/toy/extensions/boolean.rb
toystore-0.8.0 lib/toy/extensions/boolean.rb
toystore-0.7.0 lib/toy/extensions/boolean.rb
toystore-0.6.6 lib/toy/extensions/boolean.rb
toystore-0.6.5 lib/toy/extensions/boolean.rb
toystore-0.6.4 lib/toy/extensions/boolean.rb
toystore-0.6.3 lib/toy/extensions/boolean.rb
toystore-0.6.2 lib/toy/extensions/boolean.rb
toystore-0.6.1 lib/toy/extensions/boolean.rb
toystore-0.6 lib/toy/extensions/boolean.rb
toystore-0.5 lib/toy/extensions/boolean.rb