class VagrantCloud::Response::Search
Attributes
account[R]
@return [Account]
search_parameters[R]
@return [Hash] search parameters
Public Class Methods
new(account:, params:, **opts)
click to toggle source
Calls superclass method
VagrantCloud::Data::Immutable::new
# File lib/vagrant_cloud/response/search.rb, line 11 def initialize(account:, params:, **opts) if !account.is_a?(Account) raise TypeError, "Expected type `#{Account.name}` but received `#{account.class.name}`" end @account = account @search_parameters = params opts[:boxes] = reload_boxes(opts[:boxes]) super(**opts) end
Public Instance Methods
next()
click to toggle source
@return [Search] next page of search results
# File lib/vagrant_cloud/response/search.rb, line 40 def next account.searcher.from_response(self) do |s| s.next_page end end
page()
click to toggle source
@return [Integer]
# File lib/vagrant_cloud/response/search.rb, line 23 def page pg = @search_parameters.fetch(:page, 0).to_i pg > 0 ? pg : 1 end
previous()
click to toggle source
@return [Search] previous page of search results
# File lib/vagrant_cloud/response/search.rb, line 29 def previous if page <= 1 raise ArgumentError, "Cannot request page results less than one" end account.searcher.from_response(self) do |s| s.prev_page end end
Protected Instance Methods
reload_boxes(boxes)
click to toggle source
Load all the box data into proper instances
# File lib/vagrant_cloud/response/search.rb, line 49 def reload_boxes(boxes) org_cache = {} boxes.map do |b| org_name = b[:username] if !org_cache[org_name] org_cache[org_name] = account.organization(name: org_name) end org = org_cache[org_name] box = Box.new(organization: org, **b) org.boxes = org.boxes + [box] org.clean! box end end