Sha256: 9ba22ab876c8a2f195b7b9f552e71adb4695448a2227240095545561f7c914fa

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

require "rails/generators/active_record"

module Pliable
  module Generators
    class ModelGenerator < Rails::Generators::Base
      include Rails::Generators::Migration

      def self.next_migration_number(path)
        @migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i.to_s
      end

      source_root File.expand_path("../templates", __FILE__)

      def add_initializer
        create_file "config/initializers/pliable.rb", "Pliable.configure do |config|
  # define extra scrubbing for ply_name here.  This is for the purpose of making scopes.
  # For instance, if your models ply name is something like 'Invoice__c'
  # you will need to gsub '__c' off the end:
  # config.added_scrubber {|name| name.gsub('__c', '') }
end"
      end

      def generate_ply_and_relation_model
        Rails::Generators.invoke("active_record:model", ["Ply", "--parent", "pliable/ply",  "--no-migration" ])
      end

      def generate_migration
        # TODO only run if migration dosn't exist
        migration_template "migration.rb", "db/migrate/create_plies_and_ply_relations"
      end

      def run_migrations
        unless (ActiveRecord::Base.connection.table_exists?('plies') && (ActiveRecord::Base.connection.table_exists? 'ply_relations'))
          rake("db:migrate db:test:prepare")
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pliable-0.2.1 lib/generators/pliable/model_generator.rb
pliable-0.2.0 lib/generators/pliable/model_generator.rb
pliable-0.1.0 lib/generators/pliable/model_generator.rb