Module: Fluent::Factory

Includes:
Workflow
Defined in:
lib/fluent/factory.rb

Instance Method Summary collapse

Methods included from Workflow

def_caller, included, #perform_workflow, #work_item_index_for, #workflow_for, #workflow_path_for

Instance Method Details

#get_object_for(definition) ⇒ Object



83
84
85
86
87
# File 'lib/fluent/factory.rb', line 83

def get_object_for(definition)
  definition.split('::').inject(Object) do |obj, name|
    obj.const_get(name)
  end
end

#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 within the context of the definition

Returns:

  • (Object)

    instance of the definition



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fluent/factory.rb', line 14

def on(definition, visit=false, &block)
  definition = get_object_for(definition) if definition.is_a? String
  
  if @active.kind_of?(definition)
    block.call @active if block
    return @active
  end
  
  if @context.kind_of?(definition)
    block.call @context if block
    return @context
  end
  
  @active = definition.new(@driver, visit)
  block.call @active if block
  
  @active
end

#on_new(definition, visit = false, &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

  • visit (Boolean) (defaults to: false)

    true if the context needs to be called into view

  • block (Proc)

    logic to execute within the context of the definition

Returns:

  • (Object)

    instance of the definition



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fluent/factory.rb', line 44

def on_new(definition, visit=false, &block)
  definition = get_object_for(definition) if definition.is_a? String
  
  if @context.kind_of?(definition)
    @context = nil
  end
  
  @active = definition.new(@driver, visit)
  block.call @active if block

  @active
end

#on_set(definition, visit = false, &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

  • visit (Boolean) (defaults to: false)

    true if the context needs to be called into view

  • block (Proc)

    logic to execute within the context of the definition

Returns:

  • (Object)

    instance of the definition



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

def on_set(definition, visit=false, &block)
  on(definition, visit, &block)
  @context = @active
  @active
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 within the context of the definition



62
63
64
# File 'lib/fluent/factory.rb', line 62

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