Class: EY::Collection::Abstract
- Includes:
- Enumerable
- Defined in:
- lib/engineyard/collection/abstract.rb
Direct Known Subclasses
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
-
.ambiguous_error ⇒ Object
Returns the value of attribute ambiguous_error.
-
.invalid_error ⇒ Object
Returns the value of attribute invalid_error.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(contents) ⇒ Abstract
constructor
A new instance of Abstract.
- #match_one(name_part) ⇒ Object
- #match_one!(name_part) ⇒ Object
- #named(name, account_name = nil) ⇒ Object
- #to_a ⇒ Object
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_error ⇒ Object
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_error ⇒ Object
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, account_name=nil) candidates = @contents.find_all do |x| if account_name x.name.downcase == name.downcase && x.account.name.downcase == account_name.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_a ⇒ Object
21 22 23 |
# File 'lib/engineyard/collection/abstract.rb', line 21 def to_a @contents end |