Class: SampleModels::AttributeSequence
- Inherits:
-
Object
- Object
- SampleModels::AttributeSequence
- Defined in:
- lib/sample_models/attribute_sequence.rb
Direct Known Subclasses
FirstPassBaseAttributeSequence, SecondPassBaseAttributeSequence, ValidatesEmailFormatOfAttributeSequence, ValidatesInclusionOfAttributeSequence, ValidatesPresenceOfAttributeSequence, ValidatesUniquenessOfAttributeSequence
Defined Under Namespace
Classes: Builder
Class Method Summary collapse
Instance Method Summary collapse
- #belongs_to_association ⇒ Object
-
#initialize(model, column, validation, input) ⇒ AttributeSequence
constructor
A new instance of AttributeSequence.
- #next ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(model, column, validation, input) ⇒ AttributeSequence
Returns a new instance of AttributeSequence.
7 8 9 10 |
# File 'lib/sample_models/attribute_sequence.rb', line 7 def initialize(model, column, validation, input) @model, @column, @validation, @input = model, column, validation, input @number = 0 end |
Class Method Details
Instance Method Details
#belongs_to_association ⇒ Object
12 13 14 15 16 |
# File 'lib/sample_models/attribute_sequence.rb', line 12 def belongs_to_association @model.belongs_to_associations.detect { |a| a.foreign_key == @column.name } end |
#next ⇒ Object
18 19 20 21 22 |
# File 'lib/sample_models/attribute_sequence.rb', line 18 def next @number += 1 @input.next if @input value end |
#value ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sample_models/attribute_sequence.rb', line 24 def value case @column.type when :string, :text "#{@column.name} #{@number}" when :integer belongs_to_association ? belongs_to_assoc_foreign_key_value : @number when :datetime Time.now.utc - @number.minutes when :date Date.today - @number when :float @number.to_f end end |