Sha256: 1aa3ac672ca79cfea25a0701a78c360a20326d86c3d49716033be38bce5fae24

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 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"
  class_option :events, :aliases => "-e",:type => :numeric, :desc => "Number of events sent in one package to Beholder", :default => "1"
  
  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 events_exp
    s = if options[:events]
      "#{options[:events]}"
    else
      "1"
    end
  end
  
  def generate_initializer
    template 'initializer.rb', 'config/initializers/eotb.rb'
  end
  
  def api_key_configured?
    File.exists?('config/initializers/eotb.rb')
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eotb-0.5.11 lib/generators/eotb/eotb_generator.rb
eotb-0.5.10 lib/generators/eotb/eotb_generator.rb
eotb-0.5.9 lib/generators/eotb/eotb_generator.rb
eotb-0.5.8 lib/generators/eotb/eotb_generator.rb