Sha256: 8127d54ad1485f73ce0455a117367b05ec0447ab252a8121385dfbca3472dd08

Contents?: true

Size: 1.22 KB

Versions: 22

Compression:

Stored size: 1.22 KB

Contents

require "alchemy/shell"

module Alchemy
  class Seeder
    extend Alchemy::Shell

    class << self

      # This seed builds the necessary page structure for alchemy in your database.
      # Run the alchemy:db:seed rake task to seed your database.
      def seed!
        create_default_site
        create_root_page
      end

    protected

      def create_default_site
        desc "Creating default Alchemy site"
        if Alchemy::Site.count == 0
          site = Alchemy::Site.new(
            name: 'Default Site',
            host: '*'
          )
          if Alchemy::Language.any?
            site.languages = Alchemy::Language.all
          end
          site.save!
          log "Created default Alchemy site with default language."
        else
          log "Default Alchemy site was already present.", :skip
        end
      end

      def create_root_page
        desc "Creating Alchemy root page"
        root = Alchemy::Page.find_or_initialize_by(name: 'Root')
        root.do_not_sweep = true
        if root.new_record?
          if root.save!
            log "Created Alchemy root page."
          end
        else
          log "Alchemy root page was already present.", :skip
        end
      end

    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
alchemy_cms-3.1.3 lib/alchemy/seeder.rb
alchemy_cms-3.2.0.beta lib/alchemy/seeder.rb
alchemy_cms-3.1.1 lib/alchemy/seeder.rb
alchemy_cms-3.0.4 lib/alchemy/seeder.rb
alchemy_cms-3.1.0 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.rc3 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.rc2 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.rc1 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.beta6 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.beta5 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.beta4 lib/alchemy/seeder.rb
alchemy_cms-3.0.3 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.beta3 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.beta2 lib/alchemy/seeder.rb
alchemy_cms-3.1.0.beta1 lib/alchemy/seeder.rb
alchemy_cms-3.0.2 lib/alchemy/seeder.rb
alchemy_cms-3.0.1 lib/alchemy/seeder.rb
alchemy_cms-3.0.0 lib/alchemy/seeder.rb
alchemy_cms-3.0.0.rc8 lib/alchemy/seeder.rb
alchemy_cms-3.0.0.rc7 lib/alchemy/seeder.rb