Class: SchemaExpectations::ActiveRecord::ColumnReflector

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_expectations/active_record/column_reflector.rb

Overview

:nodoc:

Instance Method Summary collapse

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_namesObject



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_nullObject



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_scopesObject



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_defaultObject



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