Class: SchemaExpectations::ActiveRecord::ColumnReflector
- Inherits:
-
Object
- Object
- SchemaExpectations::ActiveRecord::ColumnReflector
- Defined in:
- lib/schema_expectations/active_record/column_reflector.rb
Overview
:nodoc:
Instance Method Summary collapse
- #column_names ⇒ Object
- #for_attributes(*attributes) ⇒ Object
-
#initialize(model, columns = nil) ⇒ ColumnReflector
constructor
A new instance of ColumnReflector.
- #not_null ⇒ Object
- #unique_scopes ⇒ Object
- #without_present_default ⇒ Object
Constructor Details
#initialize(model, columns = nil) ⇒ ColumnReflector
Returns a new instance of ColumnReflector.
6 7 8 9 |
# File 'lib/schema_expectations/active_record/column_reflector.rb', line 6 def initialize(model, columns = nil) @model = model @columns = columns || model.columns end |
Instance Method Details
#column_names ⇒ Object
11 12 13 |
# File 'lib/schema_expectations/active_record/column_reflector.rb', line 11 def column_names @columns.map { |column| column.name.to_sym } end |
#for_attributes(*attributes) ⇒ Object
19 20 21 |
# File 'lib/schema_expectations/active_record/column_reflector.rb', line 19 def for_attributes(*attributes) new_with_columns attributes_to_columns(*attributes) end |
#not_null ⇒ Object
15 16 17 |
# File 'lib/schema_expectations/active_record/column_reflector.rb', line 15 def not_null new_with_columns @columns.reject(&:null) end |
#unique_scopes ⇒ Object
27 28 29 |
# File 'lib/schema_expectations/active_record/column_reflector.rb', line 27 def unique_scopes unique_indexes.map { |index| index.columns.map(&:to_sym).sort }.sort end |
#without_present_default ⇒ Object
23 24 25 |
# File 'lib/schema_expectations/active_record/column_reflector.rb', line 23 def without_present_default new_with_columns @columns.reject(&method(:present_default_column?)) end |