Sha256: c7e7857afa93d1148426dda02d9d75b9b235295a6c7483099f05286927afbdd0

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 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 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[: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

3 entries across 3 versions & 1 rubygems

Version Path
eotb-0.5.16 bin/eotb
eotb-0.5.15 bin/eotb
eotb-0.5.14 bin/eotb