Class: SampleModels::AttributeSequence::SecondPassBelongsToSource

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

Instance Method Summary collapse

Methods inherited from AbstractSource

#next

Constructor Details

#initialize(model, assoc) ⇒ SecondPassBelongsToSource

Returns a new instance of SecondPassBelongsToSource.



137
138
139
140
# File 'lib/sample_models/attribute_sequence.rb', line 137

def initialize(model, assoc)
  super()
  @model, @assoc = model, assoc
end

Instance Method Details

#valueObject



142
143
144
145
146
147
148
# File 'lib/sample_models/attribute_sequence.rb', line 142

def value
  assoc_klass = @assoc.klass
  unless assoc_klass == @model.ar_class
    record = (assoc_klass.last || assoc_klass.sample)
    record.id
  end
end