Class: Roebe::Shell::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/roebe/shell/session/session.rb

Overview

Roebe::Session

Instance Method Summary collapse

Constructor Details

#initialize(use_colours = true, run_already = true) ⇒ Session

#

initialize

This is instantiated like so:

@session = Roebe::Shell::Session.new
#


39
40
41
42
43
44
45
46
# File 'lib/roebe/shell/session/session.rb', line 39

def initialize(
    use_colours = true,
    run_already = true
  )
  reset
  set_use_colours(use_colours)
  run if run_already
end

Instance Method Details

#[](i) ⇒ Object

#

Roebe::Shell::Session[]

#


196
197
198
# File 'lib/roebe/shell/session/session.rb', line 196

def [](i)
  @hash_ivars[i]
end

#consider_enabling_coloursObject

#

consider_enabling_colours

#


73
74
75
# File 'lib/roebe/shell/session/session.rb', line 73

def consider_enabling_colours
  enable_colours if @use_colours
end

#disable_coloursObject

#

disable_colours

#


140
141
142
# File 'lib/roebe/shell/session/session.rb', line 140

def disable_colours
  @use_colours = false
end

#enable_coloursObject

#

enable_colours

#


133
134
135
# File 'lib/roebe/shell/session/session.rb', line 133

def enable_colours
  @use_colours = true
end

#has_this_variable?(i) ⇒ Boolean Also known as: has_this_key?

#

has_this_variable?

Query the hash that contains the ivars whether the given key passed is included in the hash.

#

Returns:

  • (Boolean)


125
126
127
128
# File 'lib/roebe/shell/session/session.rb', line 125

def has_this_variable?(i)
  i.prepend('@') unless i.start_with? '@'
  @hash_ivars.has_key? i
end

#hash_ivars?Boolean Also known as: hash?, ivars?

#

hash_ivars?

#

Returns:

  • (Boolean)


147
148
149
# File 'lib/roebe/shell/session/session.rb', line 147

def hash_ivars?
  @hash_ivars
end

#reportObject

#

report

We bundle together several report-statements here.

#


182
183
184
# File 'lib/roebe/shell/session/session.rb', line 182

def report
  report_ivars
end

#report_ivarsObject

#

report_ivars

#


155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/roebe/shell/session/session.rb', line 155

def report_ivars
  if @hash_ivars.empty?
    e 'We do not have any instance variable stored.'
  else
    e "The available ('#{simp('environment-defined')}) instance "\
      "variables are:"
    ivars?.each_pair {|key, value|
      the_type = value.class # This is the class, such as Range.
      value = value.inspect # String representation required for display-purposes.
      e '  '+simp(key)+' -> '+value+' ('+simp(the_type.to_s)+')'
    }
  end
end

#resetObject

#

reset

#


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/roebe/shell/session/session.rb', line 51

def reset
  # ======================================================================= #
  # === @use_colours
  # ======================================================================= #
  @use_colours = true
  # ======================================================================= #
  # === @hash_ivars
  # ======================================================================= #
  @hash_ivars  = {} # The instance variables.
  @hash_lvars  = {} # The local variables.
end

#runObject

#

run

#


189
190
191
# File 'lib/roebe/shell/session/session.rb', line 189

def run
  consider_enabling_colours
end

#set_this_ivar(name_of_ivar, value) ⇒ Object Also known as: set

#

set_this_ivar

Usage examples from within the Roebe Shell:

@foo = 5; @bar = 'hi'; ses?

Usage examples:

@session.set_this_ivar('foo','value_here')
@session.set_this_ivar('bar','5')
#


90
91
92
93
94
95
96
# File 'lib/roebe/shell/session/session.rb', line 90

def set_this_ivar(name_of_ivar, value)
  name_of_ivar = name_of_ivar.to_s # We always require a String.
  unless name_of_ivar.start_with? '@'
    name_of_ivar.prepend '@'
  end
  @hash_ivars[name_of_ivar] = value # Append only if it does not yet exist.
end

#set_this_lvar(name_of_lvar, value) ⇒ Object

#

set_this_lvar

Set local variable here.

#


103
104
105
106
# File 'lib/roebe/shell/session/session.rb', line 103

def set_this_lvar(name_of_lvar, value)
  name_of_lvar = name_of_lvar.to_s # We always require a String.
  @hash_lvars[name_of_livar] = value # Append only if it does not yet exist.
end

#set_use_colours(i) ⇒ Object

#

set_use_colours

#


66
67
68
# File 'lib/roebe/shell/session/session.rb', line 66

def set_use_colours(i)
  @use_colours = i
end

#simp(i) ⇒ Object

#

simp

#


172
173
174
175
# File 'lib/roebe/shell/session/session.rb', line 172

def simp(i)
  return Colours.simp(i) if @use_colours
  i
end