Sha256: 689bf46164ebef5e13f867c8ecde7ecb7de142607bc21edc68678e4f792fabc6

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'rails/generators'

class EotbGenerator < Rails::Generators::Base

  desc "Creates eotb initializer in confing/initializers/eotb.rb, setting your app to work with Beholder."

  source_root File.expand_path('../../../../generators/eotb/templates', __FILE__)
  
  class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Beholder API key"
  
  def generator
    ensure_parameters_was_set
    generate_initializer unless api_key_configured?
    puts "Eotb is configured!"
    puts "File 'config/initializers/eotb.rb' was created!"
    puts "Start using eotb now!"
  end
    
  private

  def ensure_parameters_was_set
    if api_key_configured?
      puts "Configuration file already exists: config/initializers/eotb.rb"
      exit
    end
  end
  
  def api_key_exp
    "#{options[:api_key]}"
  end

  def generate_initializer
    template 'initializer.rb', 'config/initializers/eotb.rb'
  end
  
  def api_key_configured?
    if !options[:api_key]
      puts "Must pass --api-key='your_api_key' or -k 'your_api_key'"
      exit
    end
    File.exists?('config/initializers/eotb.rb') && options[:api_key].empty?
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eotb-0.5.18 lib/generators/eotb/eotb_generator.rb