add support for secondary sequences
I needed a way to generate invoice number with user-defined prefix. Thought that 'secondary sequences' can do that and still be useful for other use-cases.
Example
acts_as_sequenced column: :invoice_number_sequential_id,
secondary: { column: :invoice_number, value: -> (record, next_id) { "#{record.invoice_number_prefix}#{next_id}" } }
@derrickreimer I'm happy to update the README and add tests if you are ok with merging this feature. Feedback is welcome 🙂
I like the idea here, but it seems like it almost needs two separate lines.
acts_as_sequenced column: :invoice_number_sequential_id,
acts_as_sequenced column: :invoice_number, sequence: -> (record, next_id) { "#{record.invoice_number_prefix}#{next_id}" } }
I like the idea of being able to customize the sequence with a lambda. Thoughts?
I like the idea here, but it seems like it almost needs two separate lines.
acts_as_sequenced column: :invoice_number_sequential_id, acts_as_sequenced column: :invoice_number, sequence: -> (record, next_id) { "#{record.invoice_number_prefix}#{next_id}" } }I like the idea of being able to customize the sequence with a lambda. Thoughts?
Love it. Not sure about the final interface though. I have several suggestions:
1. Your suggestion
acts_as_sequenced column: :invoice_number, sequence: -> (record, next_id) { "#{record.invoice_number_prefix}#{next_id}" } }
2. Unnamed lambda
acts_as_sequenced column: :invoice_number, -> (record, next_id) { "#{record.invoice_number_prefix}#{next_id}" } }
3. Block. This looks like the most idiomatic ruby approach.
acts_as_sequenced column: :invoice_number do |record, next_id|
"#{record.invoice_number_prefix}#{next_id}"
end
I'll go with option 3. Any objections?
I like the block. One of the benefits of doing a option would be that you could pass a lambda or a symbol to have it call a method. A lot of the Rails methods support either an option with a lambda or a block, so we could support both and it would feel natural.
The biggest challenge is probably allowing multiple sequenced ids on the same model.
any idea on when this can be merged with the master?