Module: Symbiont::Factory

Defined in:
lib/symbiont/factory.rb

Instance Method Summary collapse

Instance Method Details

#on(definition, visit = false, &block) ⇒ Object Also known as: on_page, while_on

Creates a definition context for actions. If an existing context exists, that context will be re-used.

Parameters:

  • definition (Class)

    the name of a definition class

  • visit (Boolean) (defaults to: false)

    true if the context needs to be called into view

  • block (Proc)

    logic to execute in the context of the definition

Returns:

  • (Object)

    instance of the definition



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/symbiont/factory.rb', line 10

def on(definition, visit=false, &block)
  if @page.kind_of?(definition)
    block.call @page if block
    return @page
  end

  if @context.kind_of?(definition)
    block.call @context if block

    unless @page.kind_of?(definition)
      @page = @context
    end

    return @context
  end

  @page = definition.new(@browser)
  @page.view if visit == true

  @page.has_correct_url? if @page.respond_to?(:url_matches)
  @page.has_correct_title? if @page.respond_to?(:title_is)

  block.call @page if block

  @page
end

#on_new(definition, &block) ⇒ Object

Creates a definition context for actions. Unlike the on() factory, on_new will always create a new context and will never re-use an existing one.

Parameters:

  • definition (Class)

    the name of a definition class

  • block (Proc)

    logic to execute in the context of the definition

Returns:

  • (Object)

    instance of the definition



59
60
61
62
63
64
65
66
67
# File 'lib/symbiont/factory.rb', line 59

def on_new(definition, &block)
  @page = nil

  if @context.kind_of?(definition)
    @context = nil
  end
  
  on(definition, &block)
end

#on_set(definition, &block) ⇒ Object

Creates a definition context for actions. If an existing context exists, that context will be re-used. This also sets a context that will be used for that definition even if the active definition changes.

Parameters:

  • definition (Class)

    the name of a definition class

  • block (Proc)

    logic to execute within the context of the definition

Returns:

  • (Object)

    instance of the definition



77
78
79
80
# File 'lib/symbiont/factory.rb', line 77

def on_set(definition, &block)
  on(definition, &block)
  @context = @page
end

#on_view(definition, &block) ⇒ Object Also known as: on_visit

Creates a definition context for actions and establishes the context for display.

Parameters:

  • definition (Class)

    the name of a definition class

  • block (Proc)

    logic to execute in the context of the definition

Returns:

  • (Object)

    instance of the definition



46
47
48
# File 'lib/symbiont/factory.rb', line 46

def on_view(definition, &block)
  on(definition, true, &block)
end