Sha256: 61f441bf97b7526d3ad5470382a54688007c29e2238c1003130bd430deb8569c

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

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

class RulesEngineGenerator < 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?
      puts 'open doc/README.rules_engine for more instructions'
      puts ''
    end
    if @rule_name.nil?    
      puts 'run >script/generate rules_engine simple [rule name]'
      puts 'run >script/generate rules_engine complex [rule name]'
      puts ''
      puts "or install the rules_engine_templates gem to see other templates"
      puts ''
    else
      puts 'run >rake spec to test the new rule'  
      puts ''
    end      
  end

  def manifest
    record do |m|
      if @rule_type.nil?
        RulesEngineManifest.populate_record(m)
      elsif !@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

8 entries across 8 versions & 1 rubygems

Version Path
rules_engine-0.2.0 rails_generators/rules_engine_generator.rb
rules_engine-0.1.10 rails_generators/rules_engine_generator.rb
rules_engine-0.1.9 rails_generators/rules_engine_generator.rb
rules_engine-0.1.8 rails_generators/rules_engine_generator.rb
rules_engine-0.1.7 rails_generators/rules_engine_generator.rb
rules_engine-0.1.6 rails_generators/rules_engine_generator.rb
rules_engine-0.1.5 rails_generators/rules_engine_generator.rb
rules_engine-0.1.4 rails_generators/rules_engine_generator.rb