Sha256: e20710fa1d15899fe3710cd260a8c162d00652159f6e6a2699db6aef99569a53

Contents?: true

Size: 1.33 KB

Versions: 16

Compression:

Stored size: 1.33 KB

Contents

module SitemapGenerator
  module Utilities
    extend self

    # Copy templates/sitemap.rb to config if not there yet.
    def install_sitemap_rb(verbose=false)
      if File.exist?(SitemapGenerator.app.root + 'config/sitemap.rb')
        puts "already exists: config/sitemap.rb, file not copied" if verbose
      else
        FileUtils.cp(
          SitemapGenerator.templates.template_path(:sitemap_sample),
          SitemapGenerator.app.root + 'config/sitemap.rb')
        puts "created: config/sitemap.rb" if verbose
      end
    end

    # Remove config/sitemap.rb if exists.
    def uninstall_sitemap_rb
      if File.exist?(SitemapGenerator.app.root + 'config/sitemap.rb')
        File.rm(SitemapGenerator.app.root + 'config/sitemap.rb')
      end
    end

    # Clean sitemap files in output directory.
    def clean_files
      FileUtils.rm(Dir[SitemapGenerator.app.root + 'public/sitemap*.xml.gz'])
    end

    # Validate all keys in a hash match *valid keys, raising ArgumentError on a
    # mismatch. Note that keys are NOT treated indifferently, meaning if you use
    # strings for keys but assert symbols as keys, this will fail.
    def assert_valid_keys(hash, *valid_keys)
      unknown_keys = hash.keys - [valid_keys].flatten
      raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sitemap_generator-2.2.1 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.8 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.7 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.7.pre1 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.6 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.5 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.4 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.3 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.2 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.1 lib/sitemap_generator/utilities.rb
sitemap_generator-2.1.0 lib/sitemap_generator/utilities.rb
sitemap_generator-2.0.1.pre2 lib/sitemap_generator/utilities.rb
sitemap_generator-2.0.1.pre1 lib/sitemap_generator/utilities.rb
sitemap_generator-2.0.1 lib/sitemap_generator/utilities.rb
sitemap_generator-2.0.0 lib/sitemap_generator/utilities.rb
sitemap_generator-1.5.2 lib/sitemap_generator/utilities.rb