Module: Sequel::Plugins::BooleanReaders
- Defined in:
- lib/sequel/plugins/boolean_readers.rb
Overview
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_BOOLEAN_ATTRIBUTE_PROC =
Default proc for determining if given column is a boolean, which just checks that the :type is boolean.
lambda{|c| s = db_schema[c] and s[:type] == :boolean}
Class Method Summary collapse
-
.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.
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.
22 23 24 25 |
# File 'lib/sequel/plugins/boolean_readers.rb', line 22 def self.configure(model, &block) model.(:boolean_attribute?, &(block || DEFAULT_BOOLEAN_ATTRIBUTE_PROC)) model.instance_eval{send(:create_boolean_readers) if @dataset} end |