Class: EY::Collection::Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/engineyard/collection/abstract.rb

Direct Known Subclasses

Apps, Environments

Constant Summary collapse

COLLAB_MESSAGE =
<<-MSG
\nThis error is due to having access to another account's resources via the collaboration feature.
Specify --account ACCOUNT_NAME to resolve this ambiguity.
MSG

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Abstract

Returns a new instance of Abstract.



13
14
15
# File 'lib/engineyard/collection/abstract.rb', line 13

def initialize(contents)
  @contents = contents ? contents.dup.flatten : []
end

Class Attribute Details

.ambiguous_errorObject

Returns the value of attribute ambiguous_error.



58
59
60
# File 'lib/engineyard/collection/abstract.rb', line 58

def ambiguous_error
  @ambiguous_error
end

.invalid_errorObject

Returns the value of attribute invalid_error.



58
59
60
# File 'lib/engineyard/collection/abstract.rb', line 58

def invalid_error
  @invalid_error
end

Instance Method Details

#each(&block) ⇒ Object



17
18
19
# File 'lib/engineyard/collection/abstract.rb', line 17

def each(&block)
  @contents.each(&block)
end

#match_one(name_part) ⇒ Object



39
40
41
# File 'lib/engineyard/collection/abstract.rb', line 39

def match_one(name_part)
  named(name_part) || find_by_unambiguous_substring(name_part)
end

#match_one!(name_part) ⇒ Object



43
44
45
# File 'lib/engineyard/collection/abstract.rb', line 43

def match_one!(name_part)
  match_one(name_part) or raise invalid_error(name_part)
end

#named(name, account_name = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/engineyard/collection/abstract.rb', line 25

def named(name, =nil)
  candidates = @contents.find_all do |x|
    if 
      x.name.downcase == name.downcase && x..name.downcase == .downcase
    else
      x.name.downcase == name.downcase
    end
  end
  if candidates.size > 1
    raise ambiguous_error(name, candidates.map {|e| e.name}, COLLAB_MESSAGE )
  end
  candidates.first
end

#to_aObject



21
22
23
# File 'lib/engineyard/collection/abstract.rb', line 21

def to_a
  @contents
end