Method: Tap::Support::Manifest#search

Defined in:
lib/tap/support/manifest.rb

#search(key) ⇒ Object

Search across env.each for the first entry minimatching key. A single env can be specified by using a compound key like ‘env_key:key’. Returns nil if no matching entry is found.

Search raises an error unless bound?



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/tap/support/manifest.rb', line 123

def search(key)
  raise "cannot search unless bound" unless bound?
  
  key =~ SEARCH_REGEXP
  envs = if $4 != nil
    # compound key, match for env
    key = $4
    [env.minimatch($1)].compact
  else
    # not a compound key, search all
    # envs by iterating env itself
    env
  end
  
  # traverse envs looking for the first
  # manifest entry matching key
  envs.each do |env|
    if result = env.send(reader).minimatch(key)
      return result
    end
  end
  
  nil
end