Class: PrettyId::Generator
- Inherits:
-
Object
- Object
- PrettyId::Generator
- Defined in:
- lib/pretty_id/generator.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(record) ⇒ Generator
constructor
A new instance of Generator.
- #length ⇒ Object
- #prefix ⇒ Object
- #separator ⇒ Object
Constructor Details
#initialize(record) ⇒ Generator
Returns a new instance of Generator.
5 6 7 |
# File 'lib/pretty_id/generator.rb', line 5 def initialize(record) @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/pretty_id/generator.rb', line 3 def record @record end |
Instance Method Details
#id ⇒ Object
9 10 11 |
# File 'lib/pretty_id/generator.rb', line 9 def id "#{prefix}#{separator}#{SecRandom.alphanumeric(length)}" end |
#length ⇒ Object
13 14 15 |
# File 'lib/pretty_id/generator.rb', line 13 def length 12 end |
#prefix ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/pretty_id/generator.rb', line 17 def prefix if record.class.id_prefix.is_a? Proc record.class.id_prefix.call(record) else record.class.id_prefix end end |
#separator ⇒ Object
25 26 27 |
# File 'lib/pretty_id/generator.rb', line 25 def separator record.class.id_separator end |