Gem Version Build Status Coverage Status Dependency Status

SchemaPlus::Columns

SchemaPlus::Columns adds some useful accessors the objects returned by ActiveRecord's Model.columns database introspection query.

SchemaPlus::Columns is part of the SchemaPlus family of Ruby on Rails extension gems.

Installation

As usual:

gem "schema_plus_columns"                # in a Gemfile
gem.add_dependency "schema_plus_columns" # in a .gemspec

Usage

SchemaPlus::Columns makes these accessors available:

column.indexes

Returns a list of index definitions for each index that refers to this column. Returns an empty list if there are no such indexes.

column.unique?

Returns true if the column is in a unique index.

column.unique_scope

If the column is in a unique index, returns a list of names of other columns in the index. Returns an empty list if it's a single-column index. Returns nil if the column is not in a unique index.

column.case_sensitive?

Returns true if the column is in one or more indexes that are case sensitive. Requires the index definitions to respond to :case_sensitive? -- i.e. Only works with schema_plus_pg_indexes having been loaded.

column.required_on

Returns an indicator of the circumstance in which the column must have a value:

  • nil If the column may be null
  • :save If the column has no default value
  • :update Otherwise

Compatibility

SchemaPlus::Columns is tested on:

  • ruby 2.3.1 with activerecord 4.2, using mysql2, sqlite3 or postgresql
  • ruby 2.3.1 with activerecord 5.0, using mysql2, sqlite3 or postgresql
  • ruby 2.3.1 with activerecord 5.1, using mysql2, sqlite3 or postgresql
  • ruby 2.3.1 with activerecord 5.2, using mysql2, sqlite3 or postgresql

Release Notes

  • 0.3.0 - AR 5.2
  • 0.2.0 - AR 5.1 Support
  • 0.1.3 - AR 5.0 Support
  • 0.1.2 - Missing require
  • 0.1.1 - Explicit gem dependencies
  • 0.1.0 - Initial release, extracted from SchemaPlus 1.x

Development & Testing

Are you interested in contributing to SchemaPlus::Columns? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.

Some things to know about to help you develop and test:

  • schema_dev: SchemaPlus::Columns uses schema_dev to facilitate running rspec tests on the matrix of ruby, activerecord, and database versions that the gem supports, both locally and on travis-ci

To to run rspec locally on the full matrix, do:

    $ schema_dev bundle install
    $ schema_dev rspec

You can also run on just one configuration at a time; For info, see schema_dev --help or the schema_dev README.

The matrix of configurations is specified in schema_dev.yml in the project root.

  • schema_plus_core: SchemaPlus::Columns uses the SchemaPlus::Core API that provides middleware callback stacks to make it easy to extend ActiveRecord's behavior. If that API is missing something you need for your contribution, please head over to schema_plus_core and open an issue or pull request.
  • schema_monkey: SchemaPlus::Columns is implemented as a schema_monkey client, using schema_monkey's convention-based protocols for extending ActiveRecord and using middleware stacks.