Class: CoolId::Config
- Inherits:
-
Object
- Object
- CoolId::Config
- Defined in:
- lib/cool_id.rb
Overview
Configuration class for CoolId generation.
Instance Attribute Summary collapse
-
#alphabet ⇒ String?
readonly
The alphabet to use for generating IDs.
-
#id_field ⇒ Symbol?
readonly
The field to use for storing the ID in the model.
-
#length ⇒ Integer?
readonly
The length of the generated ID (excluding prefix and separator).
-
#max_retries ⇒ Integer?
readonly
The maximum number of retries when generating a unique ID.
-
#model_class ⇒ Class
readonly
The ActiveRecord model class associated with this configuration.
-
#prefix ⇒ String
readonly
The prefix for generated IDs.
Instance Method Summary collapse
-
#initialize(prefix:, model_class:, length: nil, alphabet: nil, max_retries: nil, id_field: nil) ⇒ Config
constructor
Initializes a new Config instance.
Constructor Details
#initialize(prefix:, model_class:, length: nil, alphabet: nil, max_retries: nil, id_field: nil) ⇒ Config
Initializes a new Config instance.
171 172 173 174 175 176 177 178 |
# File 'lib/cool_id.rb', line 171 def initialize(prefix:, model_class:, length: nil, alphabet: nil, max_retries: nil, id_field: nil) @prefix = validate_prefix(prefix) @length = length @alphabet = validate_alphabet(alphabet) @max_retries = max_retries @model_class = model_class @id_field = id_field end |
Instance Attribute Details
#alphabet ⇒ String? (readonly)
Returns The alphabet to use for generating IDs.
153 154 155 |
# File 'lib/cool_id.rb', line 153 def alphabet @alphabet end |
#id_field ⇒ Symbol? (readonly)
Returns The field to use for storing the ID in the model.
162 163 164 |
# File 'lib/cool_id.rb', line 162 def id_field @id_field end |
#length ⇒ Integer? (readonly)
Returns The length of the generated ID (excluding prefix and separator).
150 151 152 |
# File 'lib/cool_id.rb', line 150 def length @length end |
#max_retries ⇒ Integer? (readonly)
Returns The maximum number of retries when generating a unique ID.
156 157 158 |
# File 'lib/cool_id.rb', line 156 def max_retries @max_retries end |
#model_class ⇒ Class (readonly)
Returns The ActiveRecord model class associated with this configuration.
159 160 161 |
# File 'lib/cool_id.rb', line 159 def model_class @model_class end |
#prefix ⇒ String (readonly)
Returns The prefix for generated IDs.
147 148 149 |
# File 'lib/cool_id.rb', line 147 def prefix @prefix end |