Module: PluginAWeek::AttributePredicates::Extensions::ActiveRecord

Defined in:
lib/attribute_predicates/extensions/active_record.rb

Overview

Adds support for automatically defining predicate methods using attr_predicate when defining attributes using attr, attr_reader, attr_reader, and attr_accessor. In comparison to normal Ruby attributes, ActiveRecord predicates use a different system for defining true/false.

Examples

The predicate methods for attributes use ActiveRecord’s type conversion for booleans for determing whether to return true or false. For example,

class Person < ActiveRecord::Base
  attr_accessor :value
end

p = Person.new
p.value = false
p.value?    # => false

p.value = 'false'
p.value?    # => false

p.value = 'true'
p.value?    # => true

p.value = 't'
p.value?    # => true

p.value = 1
p.value?    # => true