Method: Collins::CLI::Find#validate!

Defined in:
lib/collins/cli/find.rb

#validate!Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/collins/cli/find.rb', line 122

def validate!
  raise "Options not yet parsed with #parse!" unless @parsed
  # fix bug where assets wont get found if they dont have that meta attribute
  search_attrs.delete(:hostname) if search_attrs[:hostname].nil?
  # for any search attributes, lets not pass arrays of 1 element
  # as that will confuse as_query?
  search_attrs.each do |k,v|
    if v.is_a? Array
      search_attrs[k] = v.first if v.length == 1
      search_attrs[k] = nil if v.empty?
    end
  end

  # merge search_attrs into query
  if as_query?(search_attrs)
    query_opts[:query] = convert_to_query(query_opts[:operation], search_attrs, options)
  else
    query_opts.merge!(search_attrs)
  end
  @validated = true
  self
end