Module: Para::SeoTools::Skeleton

Extended by:
ActiveSupport::Autoload
Defined in:
lib/para/seo_tools/skeleton.rb,
lib/para/seo_tools/skeleton/page.rb,
lib/para/seo_tools/skeleton/site.rb,
lib/para/seo_tools/skeleton/worker.rb

Defined Under Namespace

Classes: Page, Site, Worker

Class Method Summary collapse

Class Method Details

.buildObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/para/seo_tools/skeleton.rb', line 33

def self.build
  return if migrating?
  return unless ActiveRecord::Base.connection.table_exists?(Para::SeoTools::Page.table_name)

  log "   * Building app skeleton pages ..."

  self.site = Skeleton::Site.new
  # Evaluate the configuration block
  site.instance_exec(&config)

  # Save all the pages to database
  ActiveRecord::Base.transaction do
    log "   * Saving generated pages ..."

    site.pages.each do |page|
      page.model.save!
    end

    log "   * Destroying old pages ..."

    # Delete pages not in skeleton
    destroy_deleted_pages!
  end
end

.destroy_deleted_pages!Object



62
63
64
65
66
67
68
69
70
# File 'lib/para/seo_tools/skeleton.rb', line 62

def self.destroy_deleted_pages!
  identifiers = site.pages.map(&:identifier)
  pages = Para::SeoTools::Page.where.not(identifier: identifiers)

  if (count = pages.count) > 0
    log "Destroying #{ count } removed pages from Skeleton"
    pages.destroy_all
  end
end

.draw(lazy: false, &block) ⇒ Object



28
29
30
31
# File 'lib/para/seo_tools/skeleton.rb', line 28

def self.draw(lazy: false, &block)
  self.config = block
  build unless lazy
end

.loadObject



19
20
21
22
23
24
25
26
# File 'lib/para/seo_tools/skeleton.rb', line 19

def self.load
  # Ensure routes are loaded to allow skeleton to call routes name helpers
  Rails.application.reload_routes!
  # Skeleton file path
  skeleton_path = Rails.root.join('config', 'skeleton.rb')
  # Load the skeleton file
  require skeleton_path if File.exists?(skeleton_path)
end

.log(message) ⇒ Object

Log messages when you’re not in rails



74
75
76
# File 'lib/para/seo_tools/skeleton.rb', line 74

def self.log(message)
  Rails.logger.info(message) if enable_logging || !$0.end_with?('rails')
end

.migrating?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/para/seo_tools/skeleton.rb', line 58

def self.migrating?
  ActiveRecord::Migrator.needs_migration?
end

.with_logging(&block) ⇒ Object



12
13
14
15
16
17
# File 'lib/para/seo_tools/skeleton.rb', line 12

def self.with_logging(&block)
  self.enable_logging = true
  block.call
ensure
  self.enable_logging = false
end