Module: Sequel::Plugins::BooleanReaders

Defined in:


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.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse


Default proc for determining if given column is a boolean, which just checks that the :type is boolean.

lambda{|c| db_schema[c][:type] == :boolean}

Class Method Summary collapse

Class Method Details

.configure(model, &block) ⇒ Object

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.

# File 'lib/sequel/lib/sequel/plugins/boolean_readers.rb', line 22

def self.configure(model, &block)
  model.meta_def(:boolean_attribute?, &(block || DEFAULT_BOOLEAN_ATTRIBUTE_PROC))
  model.instance_eval{send(:create_boolean_readers) if @dataset}