Class: Seofy::Adapters::Base36
- Defined in:
- lib/seofy/adapters/base36.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base36
constructor
A new instance of Base36.
- #seofy_slug(inst) ⇒ Object
- #set_seofy_slug(inst) ⇒ Object
Methods inherited from Base
#after_create, #before_create, #need_update_slug?
Constructor Details
#initialize(options = {}) ⇒ Base36
Returns a new instance of Base36.
5 6 7 8 |
# File 'lib/seofy/adapters/base36.rb', line 5 def initialize(={}) super() @length = [:length] end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
4 5 6 |
# File 'lib/seofy/adapters/base36.rb', line 4 def column @column end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
4 5 6 |
# File 'lib/seofy/adapters/base36.rb', line 4 def length @length end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/seofy/adapters/base36.rb', line 4 def @options end |
Instance Method Details
#seofy_slug(inst) ⇒ Object
10 11 12 |
# File 'lib/seofy/adapters/base36.rb', line 10 def seofy_slug(inst) inst.send(self.column) end |
#set_seofy_slug(inst) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/seofy/adapters/base36.rb', line 14 def set_seofy_slug(inst) slug_exist = true while slug_exist random = ::Seofy::Encoders::Base36.random(self.length) if inst.class.unscoped.exists?(["#{column} = ?", random]) slug_exist = true else inst.send("#{column}=", random) slug_exist = false end end end |