Class: EotbConfigurator

Inherits:
Object
  • Object
show all
Defined in:
bin/eotb

Instance Method Summary collapse

Instance Method Details

#configure(args) ⇒ Object



46
47
48
49
50
51
52
53
# File 'bin/eotb', line 46

def configure args
  @args = args
  parse_options
  ensure_parameter_was_set
  recognize_rails_version
  command = prepare_command
  system( command )
end

#ensure_parameter_was_setObject



27
28
29
30
31
32
# File 'bin/eotb', line 27

def ensure_parameter_was_set
  if !@app[:apikey]
    puts "Must pass --api-key or file config/initializers/eotb.rb already exists"
    exit
  end
end

#parse_optionsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'bin/eotb', line 7

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

#prepare_commandObject



34
35
36
37
38
39
40
41
42
43
44
# File 'bin/eotb', line 34

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

#recognize_rails_versionObject



23
24
25
# File 'bin/eotb', line 23

def recognize_rails_version
  @version = %x( rails -v ).split[1]
end