Class: EY::Resolver::Examiner
- Inherits:
-
Object
- Object
- EY::Resolver::Examiner
- 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
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#suggestions ⇒ Object
readonly
Returns the value of attribute suggestions.
Instance Method Summary collapse
- #acc_apps ⇒ Object
- #acc_envs ⇒ Object
- #account_name ⇒ Object
-
#account_scoping_errors ⇒ Object
Account scoping is wrong.
- #accounts ⇒ Object
- #add_suggestion(app, env) ⇒ Object
- #app_name ⇒ Object
- #app_unconstrained_errors ⇒ Object
- #apps ⇒ Object
-
#association_errors ⇒ Object
App doesn’t match environment.
- #env_not_found_errors ⇒ Object
- #env_unconstrained_errors ⇒ Object
- #environment_name ⇒ Object
- #envs ⇒ Object
-
#initialize(query, user) ⇒ Examiner
constructor
A new instance of Examiner.
-
#not_found_errors ⇒ Object
Specified name was not found.
- #unconstrained_errors ⇒ Object
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
#query ⇒ Object (readonly)
Returns the value of attribute query.
9 10 11 |
# File 'lib/ey_resolver/examiner.rb', line 9 def query @query end |
#suggestions ⇒ Object (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_apps ⇒ Object
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.account_name).matches end |
#acc_envs ⇒ Object
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.account_name).matches end |
#account_name ⇒ Object
128 129 130 |
# File 'lib/ey_resolver/examiner.rb', line 128 def account_name query.account_name && query.account_name.inspect end |
#account_scoping_errors ⇒ Object
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 account_scoping_errors if !query.account_name 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 #{account_name}." 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 #{account_name}." envs.each do |env| env.apps.each do |app| add_suggestion(app, env) end end end return problems if problems.any? end |
#accounts ⇒ Object
140 141 142 |
# File 'lib/ey_resolver/examiner.rb', line 140 def accounts @accounts ||= AccountResolver.new(@user, :account_name => query.account_name).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.account.name, 'app_name' => app.name, 'environment_name' => env.name} end |
#app_name ⇒ Object
132 133 134 |
# File 'lib/ey_resolver/examiner.rb', line 132 def app_name query.app_name && query.app_name.inspect end |
#app_unconstrained_errors ⇒ Object
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 |
#apps ⇒ Object
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_errors ⇒ Object
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_errors ⇒ Object
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_errors ⇒ Object
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_name ⇒ Object
136 137 138 |
# File 'lib/ey_resolver/examiner.rb', line 136 def environment_name query.environment_name && query.environment_name.inspect end |
#envs ⇒ Object
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_errors ⇒ Object
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.account_name && accounts.empty? problems << "No account found matching #{account_name}." 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_errors ⇒ Object
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 |