Class: EYCli::Controller::Apps

Inherits:
Object
  • Object
show all
Includes:
GitUtils
Defined in:
lib/ey_cli/controllers/apps.rb

Instance Method Summary collapse

Methods included from GitUtils

#fetch_repository, #git_repository?

Instance Method Details

#create(account, base = Dir.pwd, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ey_cli/controllers/apps.rb', line 6

def create(, base = Dir.pwd, options = {})
  if git_repository?(base) || options[:git]
    app = EYCli::Model::App.create({
      :account               => ,
      'app[name]'            => options[:name] || File.basename(base),
      'app[app_type_id]'     => options[:type] || fetch_type(base).to_s,
      'app[repository_uri]'  => options[:git]  || fetch_repository(base)
    })

    if app.errors?
      EYCli.term.print_errors(app.errors, "App creation failed:")
    else
      EYCli.term.success("App '#{app.name}' created successfully")
    end
    app
  else
    EYCli.term.error("Not a git repository: #{base}")
  end
end

#fetch_app(account = nil, options = {}, base = Dir.pwd) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ey_cli/controllers/apps.rb', line 43

def fetch_app( = nil, options = {}, base = Dir.pwd)
  if 
    # search for account. Should we really care?
  else
    all_apps = fetch_apps
    return all_apps.first if all_apps.empty? || all_apps.size == 1

    app = if options[:app_name]
      EYCli::Model::App.find_by_name(options[:app_name], all_apps)
    elsif git_repository?(base)
      EYCli::Model::App.find_by_repository_uri(fetch_repository(base), all_apps)
    end

    unless app
      choice = EYCli.term.choose_resource(all_apps,
                                 "I don't know which app you want to use.",
                                 "Please, select an application:")
      app = EYCli::Model::App.find_by_name(choice, all_apps)
    end
    app
  end
end

#fetch_appsObject



66
67
68
# File 'lib/ey_cli/controllers/apps.rb', line 66

def fetch_apps
  EYCli::Model::App.all.sort_by {|app| app.name}
end

#fetch_type(base) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ey_cli/controllers/apps.rb', line 26

def fetch_type(base)
  type = if File.exist?(File.join(base, 'config.ru')) && File.exist?(File.join(base, 'config', 'environment.rb'))
    :rails3
  elsif File.exist?(File.join(base, 'config', 'environment.rb'))
    :rails2
  elsif File.exist?(File.join(base, 'config.ru'))
    :rack
  elsif File.exist?(File.join(base, 'package.json'))
    :nodejs
  else # Raise unkown application type?
    :rails3
  end

  EYCli.term.say "~> Registering #{type} application"
  type
end