Class: Seofy::TaskRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/seofy/task_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTaskRunner

Returns a new instance of TaskRunner.



4
5
6
7
# File 'lib/seofy/task_runner.rb', line 4

def initialize 
  @klasses = ENV["MODELS"]
  raise "Please provide MODELS" if @klasses.empty?
end

Instance Attribute Details

#klassesObject (readonly)

Returns the value of attribute klasses.



3
4
5
# File 'lib/seofy/task_runner.rb', line 3

def klasses
  @klasses
end

Instance Method Details

#each_modelObject



9
10
11
12
13
14
15
16
# File 'lib/seofy/task_runner.rb', line 9

def each_model
  self.klasses.split(",").each do |class_name| 
    klass = class_name.constantize
    if klass.seofy_adapter.need_update_slug?
      yield klass if block_given?
    end
  end
end

#update(record) ⇒ Object



34
35
36
37
38
# File 'lib/seofy/task_runner.rb', line 34

def update(record) 
  adapter = record.class.seofy_adapter 
  adapter.set_seofy_slug(record)
  record.class.unscoped.update_all(["#{adapter.column} = ?", adapter.seofy_slug(record)], ['id = ?', record.id])
end

#update_allObject



18
19
20
21
22
23
24
# File 'lib/seofy/task_runner.rb', line 18

def update_all
  each_model do |klass|
    klass.unscoped.find_each(:select => [:id]) do |record| 
      update(record)
    end
  end
end

#update_nullObject



26
27
28
29
30
31
32
# File 'lib/seofy/task_runner.rb', line 26

def update_null
  each_model do |klass|
    klass.unscoped.find_each(:select => [:id], :conditions => ["#{klass.seofy_adapter.column} is null"]) do |record| 
      update(record)
    end
  end
end