Class: StoryTeller::Command

Inherits:
Object show all
Includes:
CommandInitializationMethods
Defined in:
lib/story_teller/command.rb

Overview

The StoryTeller::Command class

Constant Summary

Constants included from CommandInitializationMethods

CommandInitializationMethods::CallerPattern, CommandInitializationMethods::CommandActivityTemplate, CommandInitializationMethods::CommandAntecedantTemplate, CommandInitializationMethods::CommandCauseIdentityTemplate, CommandInitializationMethods::CommandNameTemplate, CommandInitializationMethods::CommandSourceFullTemplate, CommandInitializationMethods::CommandSourceTemplate

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommandInitializationMethods

#defer, #generate_identity, #init_fields, #schedule_or_defer

Constructor Details

#initialize(params = {}, &block) ⇒ Command

Note that block if given is converted to lambda. This enables the use of return statements inside the event activity blocks.



442
443
444
445
446
447
448
449
# File 'lib/story_teller/command.rb', line 442

def initialize(params = {}, &block)
  @semaphore = Mutex.new
  init_fields(params, &block)
  init_context(@context)
  puts "Invoking #{self}"
  invoke(self)
  # @when == :immediately ? invoke(self) : schedule_or_defer(self)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def args
  @args
end

#contextObject (readonly)

Returns the value of attribute context.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def context
  @context
end

#futureObject

Returns the value of attribute future.



437
438
439
# File 'lib/story_teller/command.rb', line 437

def future
  @future
end

#identityObject (readonly)

Returns the value of attribute identity.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def identity
  @identity
end

#nameObject (readonly)

Returns the value of attribute name.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def name
  @name
end

#semaphoreObject (readonly)

Returns the value of attribute semaphore.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def semaphore
  @semaphore
end

#timeObject (readonly)

Returns the value of attribute time.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def time
  @time
end

#typeObject (readonly)

Returns the value of attribute type.



438
439
440
# File 'lib/story_teller/command.rb', line 438

def type
  @type
end

Instance Method Details

#contextualize(from) ⇒ Object



456
457
458
459
460
461
462
463
464
# File 'lib/story_teller/command.rb', line 456

def contextualize(from)
  # log.info "Initializing context for command #{self} from #{from} (#{from.class})"
  StoryTeller::Context.get.members.each do |attribute|
    value = get_value(from, attribute)
    warn_when_nilling_noun(from, attribute, value)
    setter_method = format('%<attribute>s=', attribute: attribute).to_sym
    send(setter_method, value)
  end
end

#init_context(context) ⇒ Object



451
452
453
454
# File 'lib/story_teller/command.rb', line 451

def init_context(context)
  return if context.nil?
  contextualize(context)
end