Class: Racf::Session

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

Constant Summary collapse

DEFAULT_SERVER_PORT =
23
DEFAULT_SCRIPT_PORT =
'7060'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Session

Returns a new instance of Session.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/racf/session.rb', line 13

def initialize(options)
  @user_id        = options[:user_id]
  @password       = options[:password]
  @server_address = options[:server_address]
  @verbose        = options[:verbose]
  @telnet_timeout        = options[:telnet_timeout]
  @server_port    = options[:server_port] || DEFAULT_SERVER_PORT
  @script_port    = options[:script_port] || DEFAULT_SCRIPT_PORT

  @scraper        = options[:scraper] || default_scraper
end

Instance Attribute Details

#last_error_messageObject (readonly)

Returns the value of attribute last_error_message.



11
12
13
# File 'lib/racf/session.rb', line 11

def last_error_message
  @last_error_message
end

Instance Method Details

#finishObject

Go out of ISPF shell and logoff from mainframe



35
36
37
38
39
40
41
42
# File 'lib/racf/session.rb', line 35

def finish
  Racf.logger.info("Closing RACF session")
  @scraper.action("pf 3")
  @scraper.string_action("X")
  @scraper.string_action("logoff")
  @scraper.close # a action quit faz o emulador dar exit
  Racf.logger.info("RACF session closed")
end

#remove_ispf_menu(screen) ⇒ Object

TODO Remove from the public API. In order to do it, it’s neeeded to improve the design. #theClientIsPushingUs



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/racf/session.rb', line 62

def remove_ispf_menu(screen)
  if screen.lines.first =~ /Menu\s+List\s+Mode\s+Functions\s+Utilities\s+Help/
    screen = screen.drop(8)
    screen = screen.drop_while { |line| line.match(/.*?=>.*?$/) }
  end

  screen = screen.to_s

  if screen =~ /Menu\s+List\s+Mode\s+Functions\s+Utilities\s+Help/
    screen.gsub!(/Menu\s+List\s+Mode\s+Functions\s+Utilities\s+Help.*/m, '')
  end

  screen.strip!
  screen
end

#run_command(command) ⇒ Object

Runs a RACF command and returns its raw output



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/racf/session.rb', line 46

def run_command(command)
  Racf.logger.info("Executing RACF '#{command}'")

  @scraper.string_action(command)
  raw_response = @scraper.complete_screen
  @scraper.action("enter")

  Racf.logger.info("Finished executing RACF '#{command}'")

  screen_without_menu = remove_ispf_menu(raw_response)
  screen_without_menu
end

#startObject

Start a ISPF shell session



27
28
29
30
31
# File 'lib/racf/session.rb', line 27

def start
  Racf.logger.info("Starting RACF session")
  
  load_ispf_shell
end