Sha256: 61791ac15eb6ffc1dbf13bef53864ee4df34aee63bbd4d7752459b84fe4850b7

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'rails/generators/migration'
class ActicCalendarGenerator < Rails::Generators::Base
  include Rails::Generators::Migration

  source_root File.expand_path('../templates', __FILE__)
  argument :name, :type => :string, :default => "calendar"
  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type", :required => false


   def self.next_migration_number(dirname)
     if ActiveRecord::Base.timestamped_migrations
       Time.now.utc.strftime("%Y%m%d%H%M%S")
     else
       "%.3d" % (current_migration_number(dirname) + 1)
     end
   end

   def create_migration_file
     migration_template 'migration.rb.txt', "db/migrate/create_#{table_name}.rb"
   end

  def generate_model
    if name.include? ":"
      self.attributes = name
      self.name = "calendar"
      self.attributes = format_attributes(self.attributes)
    end
    template "actic_calendar.rb.txt", "app/models/#{file_name}.rb"
  end

  private
  def file_name
    name.underscore
  end

  def table_name
    name.tableize
  end

  def format_attributes(attrs)
      fat = []
      a = attrs
      b = a.split
      b.each {|c|
      d = c.split(':')
      e = {:name => d[0], :type => d[1] }
      fat << e
      }
    fat
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
actic-0.0.2 lib/generators/actic_calendar/actic_calendar_generator.rb
actic-0.0.1 lib/generators/actic_calendar/actic_calendar_generator.rb