ey_resolver 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,21 @@ class EY::Resolver
6
6
  end
7
7
 
8
8
  class AppEnvResolver < AbstractResolver
9
+
10
+ def self.association
11
+ if Object.const_defined?(:AppDeployment)
12
+ :app_deployments
13
+ else
14
+ :app_environments
15
+ end
16
+ end
17
+
9
18
  def self.model
10
- ::AppEnvironment
19
+ if Object.const_defined?(:AppDeployment)
20
+ ::AppDeployment
21
+ else
22
+ ::AppEnvironment
23
+ end
11
24
  end
12
25
 
13
26
  def matches
@@ -20,7 +33,7 @@ class EY::Resolver
20
33
  dm_query[model.environment.name.like] = "%#{query.environment_name}%" if query.environment_name
21
34
  dm_query[model.app.account.name.like] = "%#{query.account_name}%" if query.account_name
22
35
 
23
- candidates = user.accounts.apps.app_environments.all(dm_query)
36
+ candidates = user.accounts.apps.send(self.class.association).all(dm_query)
24
37
  best_matches filter_by_remotes(candidates)
25
38
  end
26
39
 
@@ -16,9 +16,9 @@ class EY::Resolver
16
16
  end
17
17
 
18
18
  dm_query = {}
19
- dm_query[:name.like] = "%#{query.environment_name}%" if query.environment_name
20
- dm_query[model.account.name.like] = "%#{query.account_name}%" if query.account_name
21
- dm_query[model.app_environments.app.name.like] = "%#{query.app_name}%" if query.app_name
19
+ dm_query[:name.like] = "%#{query.environment_name}%" if query.environment_name
20
+ dm_query[model.account.name.like] = "%#{query.account_name}%" if query.account_name
21
+ dm_query[model.apps.name.like] = "%#{query.app_name}%" if query.app_name
22
22
 
23
23
  candidates = user.accounts.environments.all(dm_query)
24
24
 
@@ -43,18 +43,22 @@ class EY::Resolver
43
43
 
44
44
  private
45
45
 
46
+ # cache app uris since we might use it twice
47
+ def app_uris(env)
48
+ @app_uris ||= {}
49
+ @app_uris[env] ||= env.apps.map { |app| app.gitable_uri }.flatten
50
+ end
51
+
46
52
  def equivalent_remote?(env, uri)
47
- app_uris = env.apps.map { |app| app.gitable_uri }.flatten
48
- app_uris.any? { |app_uri| app_uri.equivalent?(uri) }
53
+ app_uris(env).any? { |app_uri| app_uri.equivalent?(uri) }
49
54
  end
50
55
 
51
56
  def exact_match?(env, key, val)
52
57
  case key.to_sym
53
58
  when :remotes
54
- app_uris = env.apps.map { |app| app.gitable_uri }.flatten
55
- val.any? { |uri| app_uris.any? { |app_uri| app_uri.equivalent?(uri) } }
59
+ val.any? { |uri| equivalent_remote?(env, uri) }
56
60
  when :app_name
57
- env.app_environments.any? { |app_env| app_env.app.name.downcase == val.downcase }
61
+ env.apps.any? { |app| app.name.downcase == val.downcase }
58
62
  when :environment_name
59
63
  env.name.downcase == val.downcase
60
64
  when :account_name
@@ -4,6 +4,9 @@ class EY::Resolver
4
4
  class Query
5
5
 
6
6
  def initialize(params)
7
+ unless params && params.respond_to?(:each)
8
+ raise ArgumentError, "Expected params to be a set of constraints: #{params.inspect}"
9
+ end
7
10
  self.query = params
8
11
  end
9
12
 
@@ -1,5 +1,5 @@
1
1
  module EY
2
2
  class Resolver
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,77 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ey_resolver
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Martin Emde
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-02-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- type: :runtime
23
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gitable
16
+ requirement: &70106287480080 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 17
29
- segments:
30
- - 0
31
- - 2
32
- - 3
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.2.3
34
- name: gitable
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
22
+ type: :runtime
37
23
  prerelease: false
38
- type: :development
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
24
+ version_requirements: *70106287480080
25
+ - !ruby/object:Gem::Dependency
48
26
  name: rake
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- prerelease: false
27
+ requirement: &70106287479660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
52
33
  type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ version_requirements: *70106287479660
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70106287479120 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 2
61
- - 0
62
- version: "2.0"
63
- name: rspec
64
- version_requirements: *id003
65
- description: Resolves apps, environments, app_environments and accounts using a set of constraints
66
- email:
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70106287479120
47
+ description: Resolves apps, environments, app_environments and accounts using a set
48
+ of constraints
49
+ email:
67
50
  - martin.emde@gmail.com
68
51
  executables: []
69
-
70
52
  extensions: []
71
-
72
53
  extra_rdoc_files: []
73
-
74
- files:
54
+ files:
75
55
  - .gitignore
76
56
  - Gemfile
77
57
  - README.md
@@ -98,40 +78,37 @@ files:
98
78
  - spec/app_resolver_spec.rb
99
79
  - spec/environment_resolver_spec.rb
100
80
  - spec/spec_helper.rb
101
- homepage: ""
81
+ homepage: ''
102
82
  licenses: []
103
-
104
83
  post_install_message:
105
84
  rdoc_options: []
106
-
107
- require_paths:
85
+ require_paths:
108
86
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
110
88
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
116
94
  - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ hash: 960271519958005982
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
97
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
125
103
  - 0
126
- version: "0"
104
+ hash: 960271519958005982
127
105
  requirements: []
128
-
129
106
  rubyforge_project: ey_resolver
130
107
  rubygems_version: 1.8.15
131
108
  signing_key:
132
109
  specification_version: 3
133
110
  summary: Resolves awsm models given constraints
134
- test_files:
111
+ test_files:
135
112
  - spec/account_resolver_spec.rb
136
113
  - spec/app_env_resolver_spec.rb
137
114
  - spec/app_resolver_spec.rb