class Virtus::Attribute::Boolean

Boolean attribute allows true or false values to be set Additionally it adds boolean reader method, like “admin?”

@example

class Post
  include Virtus

  attribute :published, Boolean
end

post = Post.new(:published => false)
post.published?  # => false

Public Class Methods

build_type(*) click to toggle source

@api private

# File lib/virtus/attribute/boolean.rb, line 21
def self.build_type(*)
  Axiom::Types::Boolean
end

Public Instance Methods

define_accessor_methods(attribute_set) click to toggle source

Creates an attribute reader method as a query

@param [Module] mod

@return [undefined]

@api private

# File lib/virtus/attribute/boolean.rb, line 48
def define_accessor_methods(attribute_set)
  super
  attribute_set.define_reader_method(self, "#{name}?", options[:reader])
end
value_coerced?(value) click to toggle source

Returns if the given value is either true or false

@example

boolean = Virtus::Attribute::Boolean.new(:bool)
boolean.value_coerced?(true)    # => true
boolean.value_coerced?(false)   # => true
boolean.value_coerced?(1)       # => false
boolean.value_coerced?('true')  # => false

@return [Boolean]

@api public

# File lib/virtus/attribute/boolean.rb, line 37
def value_coerced?(value)
  value.equal?(true) || value.equal?(false)
end