Sha256: 5094f090fab8a0c7a6a018f5469ab1766df18e588bab18853f04501499e75e12

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

Dir["#{File.dirname(__FILE__)}/manifests/*.rb"].each {|f| require f}

class RulesEngineTemplatesGenerator < Rails::Generator::Base

  attr_reader :rule_type
  attr_reader :rule_name, :rule_class
  
  def initialize(runtime_args, runtime_options = {})
    super
    
    @rule_type = runtime_args[0] unless runtime_args.length < 1
    @rule_name = runtime_args[1].downcase.gsub(/[^a-zA-Z0-9]+/i, '_') unless runtime_args.length < 2
    @rule_class = @rule_name.camelize unless runtime_args.length < 2
  end

  def after_generate
    puts ''
    puts '******************************************************'
    if @rule_type.nil?
      Dir["#{File.dirname(__FILE__)}/manifests/*.rb"].each do |manifest| 
        puts "run >script/generate rules_engine_templates #{File.basename(manifest, '.rb')} [rule name]"
      end      
      puts ''
    elsif @rule_name.nil?
      puts "run >script/generate rules_engine_templates #{@rule_type} [rule name]"
      puts ''
    else
      puts ''  
      klass = Kernel.const_get("#{@rule_type.classify}Manifest")
      klass.after_generate(@rule_name ,@rule_class)
      puts ''
    end
  end

  def manifest
    record do |m|
      unless @rule_type.nil? || @rule_name.nil?
        klass = Kernel.const_get("#{@rule_type.classify}Manifest")
        klass.populate_record(m, @rule_name ,@rule_class)
      end      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rules_engine_templates-0.0.6 rails_generators/rules_engine_templates_generator.rb
rules_engine_templates-0.0.5 rails_generators/rules_engine_templates_generator.rb
rules_engine_templates-0.0.4 rails_generators/rules_engine_templates_generator.rb