class DTK::Shell::ActiveContext

Constants

NO_IDENTIFIER_PROVIDED

special case when we are not able to provide valid identifier but we are using it as such

Attributes

context_list[RW]

TODO: Remove accessor for debug purpose only

Public Class Methods

new() click to toggle source
# File lib/shell/domain/active_context.rb, line 34
def initialize
  @context_list = []
end

Public Instance Methods

clear() click to toggle source
# File lib/shell/domain/active_context.rb, line 99
def clear()
  @context_list.clear
end
clone_me() click to toggle source
# File lib/shell/domain/active_context.rb, line 28
def clone_me()
  inst = ActiveContext.new
  inst.context_list = @context_list.clone
  return inst
end
command_list() click to toggle source
# File lib/shell/domain/active_context.rb, line 75
def command_list()
  filtered_entities = @context_list.select { |e| e.is_command? }
  return filtered_entities.collect { |e| e.entity.to_s }
end
commands_that_have_identifiers() click to toggle source

returns list of entities that have identifier

# File lib/shell/domain/active_context.rb, line 70
def commands_that_have_identifiers()
  filtered_entities = @context_list.select { |e| e.is_identifier? }
  return filtered_entities.collect { |e| e.entity.to_s }
end
current_alt_identifier?() click to toggle source
# File lib/shell/domain/active_context.rb, line 127
def current_alt_identifier?
  return @context_list.empty? ? false : @context_list.last.is_alt_identifier?
end
current_alt_identifier_name() click to toggle source
# File lib/shell/domain/active_context.rb, line 131
def current_alt_identifier_name
  @context_list.last.alt_identifier
end
current_command?() click to toggle source
# File lib/shell/domain/active_context.rb, line 119
def current_command?
  return @context_list.empty? ? true : @context_list.last.is_command?
end
current_identifier?() click to toggle source
# File lib/shell/domain/active_context.rb, line 123
def current_identifier?
  return @context_list.empty? ? false : @context_list.last.is_identifier?
end
empty?() click to toggle source
# File lib/shell/domain/active_context.rb, line 103
def empty?()
  return @context_list.empty?
end
find_command(entity_name) click to toggle source
# File lib/shell/domain/active_context.rb, line 55
def find_command(entity_name)
  results = @context_list.select { |e| (e.is_command? && (e.entity == entity_name.to_sym))}
  return results.first
end
find_identifier(entity_name) click to toggle source
# File lib/shell/domain/active_context.rb, line 50
def find_identifier(entity_name)
  results = @context_list.select { |e| (e.is_identifier? && (e.entity == entity_name.to_sym))}
  return results.first
end
first_command_name() click to toggle source
# File lib/shell/domain/active_context.rb, line 135
def first_command_name()
  @context_list.each do |e|
    return e.name if e.is_command?
  end

  return nil
end
first_context() click to toggle source
# File lib/shell/domain/active_context.rb, line 168
def first_context()
  return @context_list.empty? ? nil : @context_list.first
end
first_context_name() click to toggle source
# File lib/shell/domain/active_context.rb, line 164
def first_context_name()
  return @context_list.empty? ? nil : @context_list.first.name
end
full_path() click to toggle source
# File lib/shell/domain/active_context.rb, line 92
def full_path()
  path = name_list().join('/')
  path = Context.enchance_path_with_alias(path, @context_list)

  return "/#{path}"
end
get_task_cache_id() click to toggle source

returns id to be used to retrive task list form the cache based on current active context

# File lib/shell/domain/active_context.rb, line 82
def get_task_cache_id()
  identifier = command_list().join('_')
  return 'dtk' if identifier.empty?
  if current_alt_identifier?
    return "#{identifier}_#{current_alt_identifier_name()}".to_sym()
  end

  return current_identifier? ? "#{identifier}_wid".to_sym : identifier.to_sym
end
is_base_context?() click to toggle source
# File lib/shell/domain/active_context.rb, line 111
def is_base_context?
  @context_list.size == 1
end
is_n_context?() click to toggle source
# File lib/shell/domain/active_context.rb, line 107
def is_n_context?
  @context_list.size > 2
end
is_root_context?() click to toggle source
# File lib/shell/domain/active_context.rb, line 115
def is_root_context?
  @context_list.size == 0
end
is_there_identifier_for_first_context?() click to toggle source
# File lib/shell/domain/active_context.rb, line 143
def is_there_identifier_for_first_context?
  @context_list.each { |e| return true if e.is_identifier? }
  return false
end
last_command_name() click to toggle source
# File lib/shell/domain/active_context.rb, line 148
def last_command_name()
  @context_list.reverse.each do |e|
    return e.name if e.is_command?
  end

  return nil
end
last_context() click to toggle source
# File lib/shell/domain/active_context.rb, line 172
def last_context()
  return @context_list.empty? ? nil : @context_list.last
end
last_context_entity_name() click to toggle source
# File lib/shell/domain/active_context.rb, line 156
def last_context_entity_name()
  return @context_list.empty? ? nil : @context_list.last.entity
end
last_context_is_shadow_entity?() click to toggle source
# File lib/shell/domain/active_context.rb, line 176
def last_context_is_shadow_entity?
  return false if @context_list.empty?
  !!last_context().shadow_entity
end
last_context_name() click to toggle source
# File lib/shell/domain/active_context.rb, line 160
def last_context_name()
  return @context_list.empty? ? nil : @context_list.last.name
end
name_list() click to toggle source
# File lib/shell/domain/active_context.rb, line 60
def name_list()
  @context_list.collect { |e|  e.is_alt_identifier? ? e.transform_alt_identifier_name : e.name }
end
name_list_simple() click to toggle source
# File lib/shell/domain/active_context.rb, line 64
def name_list_simple()
  @context_list.collect { |e|  e.name }
end
pop_context(n) click to toggle source
# File lib/shell/domain/active_context.rb, line 46
def pop_context(n)
  return @context_list.pop(n)
end
push_new_context(context_name, entity_name, context_value=nil, shadow_entity=nil) click to toggle source
# File lib/shell/domain/active_context.rb, line 38
def push_new_context(context_name, entity_name, context_value=nil, shadow_entity=nil)
  @context_list << ContextEntity.create_context(context_name, entity_name, context_value, :id, shadow_entity)
end
push_new_name_context(context_name, entity_name, context_value=nil) click to toggle source
# File lib/shell/domain/active_context.rb, line 42
def push_new_name_context(context_name, entity_name, context_value=nil)
  @context_list << ContextEntity.create_context(context_name, entity_name, context_value, :name)
end
shadow_entity() click to toggle source
# File lib/shell/domain/active_context.rb, line 181
def shadow_entity()
  return if @context_list.empty?
  last_context().shadow_entity
end