Sha256: 41c0be58ccd872b1c937a0177dd987aa77bf8b78713e05de4fe6fb675ad9e1ec

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

#!/usr/bin/env ruby

require 'pp'
require 'optparse'

class EotbConfigurator
  def parse_options
    @app = Hash.new
    options = OptionParser.new do |opts|
      opts.on("init") do
        @action = :init
      end
      opts.on("-a", "--api-key=[ARG]", "Your API Key") do |opt|
        @app[:apikey] = opt
      end
      opts.on("-e", "--events=[ARG]", "Number of events") do |opt|
        @app[:events] = opt
      end
    end
    options.parse!(ARGV)
  end
  
  def recognize_rails_version
    @version = %x( rails -v ).split[1]
  end
  
  def ensure_parameter_was_set
    if !@app[:apikey]
      puts "Must pass --api-key or create config/initializers/eotb.rb"
      exit
    end
  end
  
  def prepare_command
    if @version >= "3"
      command = "rails generate eotb --api-key=#{@app[:apikey]}"
    else
      command = "script/generate eotb --api-key=#{@app[:apikey]}"
    end
    if @app[:events]
      command = command + " --events=#{@app[:events]}"
    end
    command
  end
  
  def configure args
    @args = args
    parse_options
    ensure_parameter_was_set
    recognize_rails_version
    command = prepare_command
    # exec( command )
    puts "Will execute: "+command
  end
end

EotbConfigurator.new.configure ARGV

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eotb-0.5.12 bin/eotb