Class: Seofy::Adapters::Base36

Inherits:
Base
  • Object
show all
Defined in:
lib/seofy/adapters/base36.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  super(options)
  @length = options[:length]
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



4
5
6
# File 'lib/seofy/adapters/base36.rb', line 4

def column
  @column
end

#lengthObject (readonly)

Returns the value of attribute length.



4
5
6
# File 'lib/seofy/adapters/base36.rb', line 4

def length
  @length
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/seofy/adapters/base36.rb', line 4

def options
  @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.exists?(["#{column} = ?", random])
      slug_exist = true
    else
      inst.send("#{column}=", random)
      slug_exist = false
    end
  end
end