Class: EY::Resolver::Examiner

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_resolver/examiner.rb

Overview

The accounts, apps, and envs lookups here are fairly “expensive” so the order we use them in is important.

For example, we don’t look at the apps matches unless app_name or remotes were specified.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, user) ⇒ Examiner

Returns a new instance of Examiner.



11
12
13
14
# File 'lib/ey_resolver/examiner.rb', line 11

def initialize(query, user)
  @query, @user = query, user
  @suggestions = []
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



9
10
11
# File 'lib/ey_resolver/examiner.rb', line 9

def query
  @query
end

#suggestionsObject (readonly)

Returns the value of attribute suggestions.



9
10
11
# File 'lib/ey_resolver/examiner.rb', line 9

def suggestions
  @suggestions
end

Instance Method Details

#acc_appsObject



148
149
150
# File 'lib/ey_resolver/examiner.rb', line 148

def acc_apps
  @acc_apps ||= AppResolver.new(@user, :app_name => query.app_name, :remotes => query.remotes, :account_name => query.).matches
end

#acc_envsObject



156
157
158
# File 'lib/ey_resolver/examiner.rb', line 156

def acc_envs
  @acc_envs ||= EnvironmentResolver.new(@user, :environment_name => query.environment_name, :remotes => query.remotes, :account_name => query.).matches
end

#account_nameObject



128
129
130
# File 'lib/ey_resolver/examiner.rb', line 128

def 
  query. && query..inspect
end

#account_scoping_errorsObject

Account scoping is wrong



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ey_resolver/examiner.rb', line 62

def 
  if !query.
    return
  end

  problems = []

  if query.app_constrained? && accounts.any? && apps.any? && acc_apps.empty?
    app_names = apps.map {|a|a.name.inspect}.join(', ')
    problems << "Application #{app_names} found, but does not exist in account #{}."
    apps.each do |app|
      app.environments.each do |env|
        add_suggestion(app, env)
      end
    end
  end

  if query.environment_name && accounts.any? && envs.any? && acc_envs.empty?
    problems << "Environment #{environment_name} found, but does not exist in account #{}."
    envs.each do |env|
      env.apps.each do |app|
        add_suggestion(app, env)
      end
    end
  end
  return problems if problems.any?
end

#accountsObject



140
141
142
# File 'lib/ey_resolver/examiner.rb', line 140

def accounts
  @accounts ||= AccountResolver.new(@user, :account_name => query.).matches
end

#add_suggestion(app, env) ⇒ Object



160
161
162
# File 'lib/ey_resolver/examiner.rb', line 160

def add_suggestion(app, env)
  @suggestions << {'account_name' => app..name, 'app_name' => app.name, 'environment_name' => env.name}
end

#app_nameObject



132
133
134
# File 'lib/ey_resolver/examiner.rb', line 132

def app_name
  query.app_name && query.app_name.inspect
end

#app_unconstrained_errorsObject



16
17
18
19
20
# File 'lib/ey_resolver/examiner.rb', line 16

def app_unconstrained_errors
  if query.app_unconstrained?
    return ["App name or repository remotes required."]
  end
end

#appsObject



144
145
146
# File 'lib/ey_resolver/examiner.rb', line 144

def apps
  @apps ||= AppResolver.new(@user, :app_name => query.app_name, :remotes => query.remotes).matches
end

#association_errorsObject

App doesn’t match environment



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ey_resolver/examiner.rb', line 101

def association_errors
  problems = []

  if query.environment_name && query.app_name && acc_envs.any? && acc_apps.any?
    problems << "Application #{app_name} and environment #{environment_name} are not associated."
    acc_envs.each do |env|
      env.apps.each do |app|
        add_suggestion(app, env)
      end
    end
    acc_apps.each do |app|
      app.environments.each do |env|
        add_suggestion(app, env)
      end
    end
  elsif query.remotes && acc_envs.any? && acc_apps.any?
    problems << "Application #{acc_apps.map {|a|a.name.inspect}.join(', ')} and environment #{environment_name} are not associated."
    acc_apps.each do |app|
      app.environments.each do |env|
        add_suggestion(app, env)
      end
    end
  end

  return problems if problems.any?
end

#env_not_found_errorsObject



90
91
92
93
94
95
96
97
98
# File 'lib/ey_resolver/examiner.rb', line 90

def env_not_found_errors
  problems = []

  if !query.environment_name && query.remotes && acc_envs.empty? && acc_apps.any?
    problems << "No environment found for applications matching remotes:" + query.remotes.map { |uri| "\n\t#{uri}" }.join
  end

  return problems if problems.any?
end

#env_unconstrained_errorsObject



22
23
24
25
26
# File 'lib/ey_resolver/examiner.rb', line 22

def env_unconstrained_errors
  if query.env_unconstrained?
    return ["Environment name, app name or repository remotes required."]
  end
end

#environment_nameObject



136
137
138
# File 'lib/ey_resolver/examiner.rb', line 136

def environment_name
  query.environment_name && query.environment_name.inspect
end

#envsObject



152
153
154
# File 'lib/ey_resolver/examiner.rb', line 152

def envs
  @envs ||= EnvironmentResolver.new(@user, :environment_name => query.environment_name, :remotes => query.remotes).matches
end

#not_found_errorsObject

Specified name was not found



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ey_resolver/examiner.rb', line 35

def not_found_errors
  problems = []

  if query. && accounts.empty?
    problems << "No account found matching #{}."
  end

  if query.app_constrained? && apps.empty?
    app_name_or_remotes =
      if app_name
        "#{app_name}."
      elsif query.remotes
        "remotes:" + query.remotes.map { |uri| "\n\t#{uri}" }.join
      else
        "no remotes."
      end
    problems << "No application found matching #{app_name_or_remotes}"
  end

  if query.environment_name && envs.empty?
    problems << "No environment found matching #{environment_name}."
  end

  return problems if problems.any?
end

#unconstrained_errorsObject



28
29
30
31
32
# File 'lib/ey_resolver/examiner.rb', line 28

def unconstrained_errors
  if query.unconstrained?
    return ["Must search by account name, app name, remotes, or environment name."]
  end
end