Sha256: 1b59c8e8762a0cc72a6909314285936f844f4336e42226892a2ed44f2be0abb4

Contents?: true

Size: 690 Bytes

Versions: 14

Compression:

Stored size: 690 Bytes

Contents

# frozen_string_literal: true

module Sail
  module Types
    # Boolean
    #
    # The Boolean type simply returns true
    # or false depending on what is stored
    # in the database.
    class Boolean < Type
      def to_value
        @setting.value == Sail::ConstantCollection::TRUE
      end

      def from(value)
        if value.is_a?(::String)
          check_for_on_or_boolean(value)
        elsif value.nil?
          Sail::ConstantCollection::FALSE
        else
          value.to_s
        end
      end

      private

      def check_for_on_or_boolean(value)
        value == Sail::ConstantCollection::ON ? Sail::ConstantCollection::TRUE : value
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sail-3.6.1 lib/sail/types/boolean.rb
sail-3.6.0 lib/sail/types/boolean.rb
sail-3.5.1 lib/sail/types/boolean.rb
sail-3.5.0 lib/sail/types/boolean.rb
sail-3.4.0 lib/sail/types/boolean.rb
sail-3.3.0 lib/sail/types/boolean.rb
sail-3.2.4 lib/sail/types/boolean.rb
sail-3.2.3 lib/sail/types/boolean.rb
sail-3.2.2 lib/sail/types/boolean.rb
sail-3.2.1 lib/sail/types/boolean.rb
sail-3.2.0 lib/sail/types/boolean.rb
sail-3.1.0 lib/sail/types/boolean.rb
sail-3.0.1 lib/sail/types/boolean.rb
sail-3.0.0 lib/sail/types/boolean.rb