Class: Promethee::LocalizeCleanService

Inherits:
Object
  • Object
show all
Defined in:
app/services/promethee/localize_clean_service.rb

Constant Summary collapse

DEFAULT_WHITELIST =
{
  "aside"            => ["searchable_visible_content", "searchable_collapsed_content", "searchable_open_label"],
  "blockquote"       => ["searchable_body", "searchable_author"],
  "collection"       => [],
  "collection_item"  => ["searchable_caption", "video"],
  "column"           => [],
  "cover"            => ["searchable_surtitle", "searchable_title", "searchable_subtitle"],
  "faq"              => [],
  "faq_item"         => ["searchable_title", "searchable_body"],
  "image"            => ["searchable_alt", "searchable_caption"],
  "page"             => ["searchable_title", "searchable_description"],
  "row"              => [],
  "slider"           => [],
  "slider_item"      => ["searchable_caption", "video"],
  "table"            => ["cols", "cols_data", "rows", "rows_data"],
  "text"             => ["searchable_body"],
  "video"            => ["url"]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name, whitelist = {}) ⇒ LocalizeCleanService

Returns a new instance of LocalizeCleanService.



24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/promethee/localize_clean_service.rb', line 24

def initialize(model_name, whitelist = {})
  begin
    model_class = model_name.constantize
    objects = model_class.all
  rescue
    puts 'Please provide a valid model name (e.g. `rake promethee:clean_localizations[Page]`)'
    exit
  end
  @objects = objects
  @whitelist = DEFAULT_WHITELIST.merge(whitelist)
end

Instance Attribute Details

#objectsObject

Returns the value of attribute objects.



22
23
24
# File 'app/services/promethee/localize_clean_service.rb', line 22

def objects
  @objects
end

Instance Method Details

#add_rule(type, attributes = []) ⇒ Object



36
37
38
# File 'app/services/promethee/localize_clean_service.rb', line 36

def add_rule(type, attributes = [])
  @whitelist[type] = attributes
end

#startObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/services/promethee/localize_clean_service.rb', line 40

def start
  puts '= START LOCALIZE CLEAN ='
  puts "Number of objects: #{objects.count}"
  i = 0
  objects.each do |object|
    next unless can_process?(object.data)

    i += 1
    puts "Processing object ##{object.id}"

    object.data = clean(object.data)
    object.save
    puts "End processing object ##{object.id}"
  end
  puts "Number of processed objects: #{i}"
  puts '====== END CLEANER ========'
end