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
# 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(enable_logging: enable_logging)
  # Evaluate the configuration block
  site.instance_exec(&config)

  # Save remaining pages and remove old pages
  ActiveRecord::Base.transaction do
    site.save

    # Delete pages not in skeleton
    destroy_deleted_pages!
  end
end

.destroy_deleted_pages!Object



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

def self.destroy_deleted_pages!
  pages = Para::SeoTools::Page.where.not(id: site.saved_pages_ids)
  log "   * Destroying old pages ..."
  pages.delete_all
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



64
65
66
# File 'lib/para/seo_tools/skeleton.rb', line 64

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

.migrating?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/para/seo_tools/skeleton.rb', line 52

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