Class: DTK::Shell::ActiveContext
- Inherits:
-
Object
- Object
- DTK::Shell::ActiveContext
- Defined in:
- lib/shell/domain/active_context.rb
Constant Summary collapse
- NO_IDENTIFIER_PROVIDED =
special case when we are not able to provide valid identifier but we are using it as such
-1
Instance Attribute Summary collapse
-
#context_list ⇒ Object
TODO: Remove accessor for debug purpose only.
Instance Method Summary collapse
- #clear ⇒ Object
- #clone_me ⇒ Object
- #command_list ⇒ Object
-
#commands_that_have_identifiers ⇒ Object
returns list of entities that have identifier.
- #current_alt_identifier? ⇒ Boolean
- #current_alt_identifier_name ⇒ Object
- #current_command? ⇒ Boolean
- #current_identifier? ⇒ Boolean
- #empty? ⇒ Boolean
- #find_command(entity_name) ⇒ Object
- #find_identifier(entity_name) ⇒ Object
- #first_command_name ⇒ Object
- #first_context ⇒ Object
- #first_context_name ⇒ Object
- #full_path ⇒ Object
-
#get_task_cache_id ⇒ Object
returns id to be used to retrive task list form the cache based on current active context.
-
#initialize ⇒ ActiveContext
constructor
A new instance of ActiveContext.
- #is_base_context? ⇒ Boolean
- #is_n_context? ⇒ Boolean
- #is_root_context? ⇒ Boolean
- #is_there_identifier_for_first_context? ⇒ Boolean
- #last_command_name ⇒ Object
- #last_context ⇒ Object
- #last_context_entity_name ⇒ Object
- #last_context_is_shadow_entity? ⇒ Boolean
- #last_context_name ⇒ Object
- #name_list ⇒ Object
- #name_list_simple ⇒ Object
- #pop_context(n) ⇒ Object
- #push_new_context(context_name, entity_name, context_value = nil, shadow_entity = nil) ⇒ Object
- #push_new_name_context(context_name, entity_name, context_value = nil) ⇒ Object
- #shadow_entity ⇒ Object
Constructor Details
#initialize ⇒ ActiveContext
Returns a new instance of ActiveContext.
34 35 36 |
# File 'lib/shell/domain/active_context.rb', line 34 def initialize @context_list = [] end |
Instance Attribute Details
#context_list ⇒ Object
TODO: Remove accessor for debug purpose only
26 27 28 |
# File 'lib/shell/domain/active_context.rb', line 26 def context_list @context_list end |
Instance Method Details
#clear ⇒ Object
99 100 101 |
# File 'lib/shell/domain/active_context.rb', line 99 def clear() @context_list.clear end |
#clone_me ⇒ Object
28 29 30 31 32 |
# 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 ⇒ Object
75 76 77 78 |
# 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 ⇒ Object
returns list of entities that have identifier
70 71 72 73 |
# 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? ⇒ Boolean
127 128 129 |
# 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 ⇒ Object
131 132 133 |
# File 'lib/shell/domain/active_context.rb', line 131 def current_alt_identifier_name @context_list.last.alt_identifier end |
#current_command? ⇒ Boolean
119 120 121 |
# 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? ⇒ Boolean
123 124 125 |
# File 'lib/shell/domain/active_context.rb', line 123 def current_identifier? return @context_list.empty? ? false : @context_list.last.is_identifier? end |
#empty? ⇒ Boolean
103 104 105 |
# File 'lib/shell/domain/active_context.rb', line 103 def empty?() return @context_list.empty? end |
#find_command(entity_name) ⇒ Object
55 56 57 58 |
# 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) ⇒ Object
50 51 52 53 |
# 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 ⇒ Object
135 136 137 138 139 140 141 |
# 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 ⇒ Object
168 169 170 |
# File 'lib/shell/domain/active_context.rb', line 168 def first_context() return @context_list.empty? ? nil : @context_list.first end |
#first_context_name ⇒ Object
164 165 166 |
# 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 ⇒ Object
92 93 94 95 96 97 |
# 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 ⇒ Object
returns id to be used to retrive task list form the cache based on current active context
82 83 84 85 86 87 88 89 90 |
# 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? ⇒ Boolean
111 112 113 |
# File 'lib/shell/domain/active_context.rb', line 111 def is_base_context? @context_list.size == 1 end |
#is_n_context? ⇒ Boolean
107 108 109 |
# File 'lib/shell/domain/active_context.rb', line 107 def is_n_context? @context_list.size > 2 end |
#is_root_context? ⇒ Boolean
115 116 117 |
# File 'lib/shell/domain/active_context.rb', line 115 def is_root_context? @context_list.size == 0 end |
#is_there_identifier_for_first_context? ⇒ Boolean
143 144 145 146 |
# 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 ⇒ Object
148 149 150 151 152 153 154 |
# 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 ⇒ Object
172 173 174 |
# 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 ⇒ Object
156 157 158 |
# 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? ⇒ Boolean
176 177 178 179 |
# 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 ⇒ Object
160 161 162 |
# 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 ⇒ Object
60 61 62 |
# 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 ⇒ Object
64 65 66 |
# File 'lib/shell/domain/active_context.rb', line 64 def name_list_simple() @context_list.collect { |e| e.name } end |
#pop_context(n) ⇒ Object
46 47 48 |
# 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) ⇒ Object
38 39 40 |
# 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) ⇒ Object
42 43 44 |
# 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 ⇒ Object
181 182 183 184 |
# File 'lib/shell/domain/active_context.rb', line 181 def shadow_entity() return if @context_list.empty? last_context().shadow_entity end |