Sha256: eacb75f22918a4c1b638648a9c4d97c2f44c9091ca0457eabdef242717b6a0e0

Contents?: true

Size: 920 Bytes

Versions: 2

Compression:

Stored size: 920 Bytes

Contents

module Sinatra
  class ModelGenerator < Sinatra::NameCommand

    def self.command
      "generate:model"
    end

    def self.help
      "model_name"
    end

    def initialize(*args)
      super
      @app_dir = File.expand_path(pwd)
    end

    def call
      path = File.expand_path(File.join(@app_dir, "models", "#{self.underscored}.rb"))
      mkdir_p File.dirname(path), verbose: true
      File.open(path, 'w') do |file|
        file.puts <<-EOF
  class #{self.classified}
    include Mongoid::Document
    include Mongoid::Timestamps

  end
        EOF
      end

      path = File.expand_path(File.join(@app_dir, "spec", "models", "#{self.underscored}_spec.rb"))
      mkdir_p File.dirname(path), verbose: true
      File.open(path, 'w') do |file|
        file.puts <<-EOF
  require 'spec_helper'

  describe #{self.classified} do
    
    it "does something"

  end
        EOF
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-template-1.2.0 lib/sinatra/commands/model_generator_command.rb
sinatra-template-1.1.0 lib/sinatra/commands/model_generator_command.rb