Sha256: 01bdaeac850245f59b3544bae97bc05d4e4daacc1a1300edb682c07d67c7eb9b

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# Stop-gap solution to allow us to keep mission-critical seed data somewhere
# accessible. Not too thrilled about it; refactor away.
module Landable
  module Seeds
    def self.seed(key)
      method_key = "seed_#{key}".to_sym
      if respond_to? method_key
        send method_key if ActiveRecord::Base.connection.schema_exists? "#{Landable.configuration.database_schema_prefix}landable"
      else
        fail NotImplementedError, "No seeds for key '#{key}'"
      end
    end

    private

    # Required data.
    def self.seed_required
      # categories ('Uncategorized' is mandatory)
      Landable::Category.where(name: 'Uncategorized').first_or_create!
      Landable.configuration.categories.each do |category_name, category_description|
        Landable::Category.where(name: category_name).first_or_create!(description: category_description)
      end
    end

    # Less required data.
    def self.seed_extras
      # themes
      Landable::Theme.where(name: 'Blank').first_or_create!(
        body: '',
        description: 'A completely blank theme; only the page body will be rendered.',
        thumbnail_url: 'http://placehold.it/300x200'
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
landable-1.14.0 lib/landable/seeds.rb
landable-1.13.2 lib/landable/seeds.rb