Sha256: 68639d6ed4bbfaf88b1c32f50b64eb6cb87b036ca6922a0936a901158cd5c5bf

Contents?: true

Size: 887 Bytes

Versions: 4

Compression:

Stored size: 887 Bytes

Contents

require 'rails/generators'

module Chive
  module Generators
    class SeedsGenerator < Rails::Generators::Base

      desc <<-DESC
Add database seeds.
      DESC

      class_option :article, type: :string, default: 'Article', desc: 'The article model'
      class_option :user, type: :string, default: 'User', desc: 'The user model'

      def manifest
        append_to_file 'db/seeds.rb' do
          <<-RUBY

# Chive examples
if Rails.env.development?
  user = #{options[:user].camelize}.create(name: 'Example', email: 'example@example.com', password: 'password')
  Chive::#{options[:article].camelize}.create(
    title: 'Hello, World!',
    body: %(
      <p>This is an example article created by the development seeds (db/seeds.rb).</p>
    ),
    author: user,
    status: 'publish',
    published_at: DateTime.now
  )
end
          RUBY
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chive-0.2.3 lib/generators/chive/seeds_generator.rb
chive-0.2.2 lib/generators/chive/seeds_generator.rb
chive-0.2.1 lib/generators/chive/seeds_generator.rb
chive-0.2.0 lib/generators/chive/seeds_generator.rb