Sha256: 3fef4bce76b5c8dc8fc7b3a88031b65b6b4711fb41b065b077a378a07430b30d

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 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("-d", "--dir=[ARG]", "Directory of app") do |opt|
        @app[:dir] = 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 file config/initializers/eotb.rb already exists"
      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[:dir]
      command = "cd "+@app[:dir]+";"+command
    end
    command
  end
  
  def configure args
    @args = args
    parse_options
    ensure_parameter_was_set
    recognize_rails_version
    command = prepare_command
    system( command )
  end
end

EotbConfigurator.new.configure ARGV

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eotb-0.5.18 bin/eotb