Module: Infrataster::Contexts

Defined in:
lib/infrataster/contexts.rb,
lib/infrataster/contexts/base_context.rb,
lib/infrataster/contexts/http_context.rb,
lib/infrataster/contexts/capybara_context.rb,
lib/infrataster/contexts/no_resource_context.rb

Defined Under Namespace

Classes: BaseContext, CapybaraContext, HttpContext, NoResourceContext

Class Method Summary collapse

Class Method Details

.from_example(example) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/infrataster/contexts.rb', line 10

def from_example(example)
  eg = example_group(example)

  server_resource = find_described(Resources::ServerResource, eg)
  resource = find_described(Resources::BaseResource, eg)

  unless server_resource || resource
    # There is neither server_resource or resource
    return nil
  end

  if server_resource && !resource
    # Server is found but resource is not found
    return Contexts::NoResourceContext.new(server_resource.server)
  end

  resource.context_class.new(server_resource.server, resource)
end