Class: SampleModels::AttributeSequence::UniquenessFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/sample_models/attribute_sequence.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, column, validation, input) ⇒ UniquenessFilter

Returns a new instance of UniquenessFilter.



174
175
176
177
# File 'lib/sample_models/attribute_sequence.rb', line 174

def initialize(model, column, validation, input)
  @model, @column, @validation, @input =
    model, column, validation, input
end

Instance Method Details

#nextObject



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/sample_models/attribute_sequence.rb', line 179

def next
  v = @input.next
  unless @validation.config[:allow_nil] && v.nil?
    unless @validation.config[:allow_blank] && v.blank?
      until @model.unique?(@column.name, v)
        v = @input.next
      end
    end
  end
  v
end

#valueObject



191
192
193
# File 'lib/sample_models/attribute_sequence.rb', line 191

def value
  self.next
end