Module: Fluent::Factory
- Defined in:
- lib/fluent/factory.rb
Instance Method Summary collapse
- #get_object_for(definition) ⇒ Object
-
#on(definition, visit = false, &block) ⇒ Object
(also: #on_page, #while_on)
Creates a definition context for actions.
-
#on_new(definition, visit = false, &block) ⇒ Object
Creates a definition context for actions.
-
#on_view(definition, &block) ⇒ Object
(also: #on_visit)
Creates a definition context for actions and establishes the context for display.
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.
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.
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.
46 47 48 |
# File 'lib/fluent/factory.rb', line 46 def on_view(definition, &block) on(definition, true, &block) end |