class DTK::Shell::ContextEntity

Constants

SHELL_SEPARATOR

Attributes

alt_identifier[RW]
entity[RW]
identifier[RW]
name[RW]
shadow_entity[RW]

Public Class Methods

create_context(context_name, entity_name, context_value=nil, type_id=:id, shadow_entity=nil) click to toggle source
# File lib/shell/domain/context_entity.rb, line 28
def self.create_context(context_name, entity_name, context_value=nil, type_id=:id, shadow_entity=nil)
  if context_value
    if :id.eql?(type_id)
      return ContextEntity.create_identifier(context_name, entity_name, context_value, shadow_entity)
    else
      return ContextEntity.create_name_identifier(context_name, entity_name, context_value, shadow_entity)
    end
  else
    return ContextEntity.create_command(context_name, entity_name, shadow_entity)
  end
end

Private Class Methods

create_command(name, entity_name, shadow_entity=nil) click to toggle source
# File lib/shell/domain/context_entity.rb, line 62
def self.create_command(name, entity_name, shadow_entity=nil)
  instance = ContextEntity.new
  instance.name   = name
  instance.entity = entity_name.to_sym
  instance.shadow_entity = shadow_entity
  return instance
end
create_identifier(name, entity_name, value, shadow_entity=nil) click to toggle source
# File lib/shell/domain/context_entity.rb, line 80
def self.create_identifier(name, entity_name, value, shadow_entity=nil)
  instance                = self.create_command(name,entity_name)
  instance.identifier     = value
  alt_identifier_name = name.to_s.split(::DTK::Client::CommandBaseThor::ALT_IDENTIFIER_SEPARATOR)
  instance.alt_identifier = alt_identifier_name.size > 1 ? alt_identifier_name.first : nil
  instance.shadow_entity  = shadow_entity
  return instance
end
create_name_identifier(name, entity_name, value, shadow_entity=nil) click to toggle source
# File lib/shell/domain/context_entity.rb, line 70
def self.create_name_identifier(name, entity_name, value, shadow_entity=nil)
  instance            = self.create_command(name,entity_name)
  instance.name           = value
  instance.identifier     = value
  instance.alt_identifier = value
  instance.shadow_entity = shadow_entity

  return instance
end

Public Instance Methods

get_identifier(type) click to toggle source
# File lib/shell/domain/context_entity.rb, line 52
def get_identifier(type)
  return (type == 'id' ? self.identifier : self.name)
end
is_alt_identifier?() click to toggle source
# File lib/shell/domain/context_entity.rb, line 44
def is_alt_identifier?
  return !@alt_identifier.nil?
end
is_command?() click to toggle source
# File lib/shell/domain/context_entity.rb, line 48
def is_command?
  return @identifier.nil?
end
is_identifier?() click to toggle source
# File lib/shell/domain/context_entity.rb, line 40
def is_identifier?
  return !@identifier.nil?
end
transform_alt_identifier_name() click to toggle source
# File lib/shell/domain/context_entity.rb, line 56
def transform_alt_identifier_name()
  @name.gsub(::DTK::Client::CommandBaseThor::ALT_IDENTIFIER_SEPARATOR, SHELL_SEPARATOR)
end