Module: Sequel::Plugins::BooleanReaders

Module | Sequel::Plugins::BooleanReaders
In: | lib/sequel/plugins/boolean_readers.rb

The BooleaReaders plugin allows for the creation of attribute? methods for boolean columns, which provide a nicer API. By default, the accessors are created for all columns of type :boolean. However, you can provide a block to the plugin to change the criteria used to determine if a column is boolean:

      Sequel::Model.plugin(:boolean_readers){|c| db_schema[c][:db_type] =~ /\Atinyint/}

This may be useful if you are using MySQL and have some tinyint columns that represent booleans and others that represent integers. You can turn the convert_tinyint_to_bool setting off and use the attribute methods for the integer value and the attribute? methods for the boolean value.

### Methods

configure

### Classes and Modules

Module Sequel::Plugins::BooleanReaders::ClassMethods

### Constants

DEFAULT_BOOLEAN_ATTRIBUTE_PROC | = | lambda{|c| db_schema[c][:type] == :boolean} |  | Default proc for determining if given column is a boolean, which just checks that the :type is boolean.

### Public Class methods

configure(model, &block)

Add the boolean_attribute? class method to the model, and create attribute? boolean reader methods for the class‘s columns if the class has a dataset.

[Source]

        # File lib/sequel/plugins/boolean_readers.rb, line 22
    22:       def self.configure(model, &block)
    23:         model.meta_def(:boolean_attribute?, &(block || DEFAULT_BOOLEAN_ATTRIBUTE_PROC))
    24:         model.instance_eval{send(:create_boolean_readers) if @dataset}
    25:       end

[Validate]