Module: Fluent::Factory

Defined in:
lib/fluent/factory.rb

Instance Method Summary collapse

Instance Method Details

#get_object_for(definition) ⇒ Object



52
53
54
55
56
# File 'lib/fluent/factory.rb', line 52

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



11
12
13
14
15
16
17
18
19
# File 'lib/fluent/factory.rb', line 11

def on(definition, visit=false, &block)
  definition = get_object_for(definition) if definition.is_a? String
  
  return @active if @active.kind_of?(definition)
  @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



32
33
34
35
36
37
38
39
# File 'lib/fluent/factory.rb', line 32

def on_new(definition, visit=false, &block)
  definition = get_object_for(definition) if definition.is_a? String

  @active = definition.new(@driver, visit)
  block.call @active if block

  @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



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

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