Class: ButlerMainframe::HostBase
- Inherits:
-
Object
- Object
- ButlerMainframe::HostBase
- Includes:
- ActiveRecord, GenericFunctions
- Defined in:
- lib/mainframe/host_base.rb,
lib/butler-mainframe.rb
Overview
This is the host class base that contains high level logic It uses sub method that have to be defined in the specific sub class
Direct Known Subclasses
Constant Summary collapse
- MAX_TERMINAL_COLUMNS =
80- MAX_TERMINAL_ROWS =
24- WAIT_AFTER_START_SESSION =
SECONDS
3
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#close_session ⇒ Object
Ends the connection and closes the session.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#wait ⇒ Object
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
-
#exec_command(cmd) ⇒ Object
Execute keyboard command like PF1 or PA2 or ENTER …
-
#get_cursor_axes ⇒ Object
Return the coordinates of the cursor.
-
#initialize(options = {}) ⇒ HostBase
constructor
A new instance of HostBase.
- #quit ⇒ Object
-
#scan(options = {}) ⇒ Object
It reads one line or an area on the screen according to parameters supplied.
-
#scan_page ⇒ Object
Scans and returns the text of the entire page.
-
#set_cursor_axes(y, x, options = {}) ⇒ Object
Move the cursor at given coordinates.
-
#wait_session(wait = nil) ⇒ Object
Sleep time between operations.
-
#write(text, options = {}) ⇒ Object
Write text on screen at the coordinates Based on the parameters provided it writes a line or an area Options: :hook => nil, :y => nil, #row :x => nil, #column :check => true, :raise_error_on_check => true, :sensible_data => nil, :clean_chars_before_writing => nil, # clean x chars before writing a value :erase_before_writing => nil # execute an erase until end of field before write a text.
Methods included from GenericFunctions
#abend?, #catch_abend, #catch_message, #catch_title, #cics?, #cics_selection, #cics_selection?, #company_menu, #company_menu?, #destination_list, #do_confirm, #do_enter, #do_erase, #do_quit, #execute_cics, #go_back, #navigate, #screen_title, #session_login, #session_login?
Methods included from ActiveRecord
Constructor Details
#initialize(options = {}) ⇒ HostBase
Returns a new instance of HostBase.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mainframe/host_base.rb', line 16 def initialize ={} = { :session_tag => ButlerMainframe.configuration.session_tag, :wait => 0.01, # wait screen in seconds :wait_debug => 2, # wait time for debug purpose :debug => false, :browser_path => ButlerMainframe.configuration.browser_path, :session_url => ButlerMainframe.configuration.session_url, :session_path => ButlerMainframe.configuration.session_path, :timeout => ButlerMainframe.configuration.timeout, :erase_before_writing => false, # execute an erase until end of field before write a text :close_session => :evaluate #:evaluate if the session is found will not be closed #:never never close the session #:always the session is always closed }.merge() @debug = [:debug] @wait = [:wait] @wait_debug = [:wait_debug] @session_tag = [:session_tag] @close_session = [:close_session] @timeout = [:timeout] @erase_before_writing = [:timeout] @action = {} @pid = nil create_object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
If is called a not existing method there is the chance that an optional module may not have been added
319 320 321 |
# File 'lib/mainframe/host_base.rb', line 319 def method_missing method_name, *args raise NoMethodError, "Method #{method_name} not found! Please check you have included any optional modules" end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
9 10 11 |
# File 'lib/mainframe/host_base.rb', line 9 def action @action end |
#close_session ⇒ Object
Ends the connection and closes the session
47 48 49 |
# File 'lib/mainframe/host_base.rb', line 47 def close_session @close_session end |
#debug ⇒ Object
Returns the value of attribute debug.
10 11 12 |
# File 'lib/mainframe/host_base.rb', line 10 def debug @debug end |
#wait ⇒ Object (readonly)
Returns the value of attribute wait.
9 10 11 |
# File 'lib/mainframe/host_base.rb', line 9 def wait @wait end |
Instance Method Details
#exec_command(cmd) ⇒ Object
Execute keyboard command like PF1 or PA2 or ENTER …
82 83 84 85 86 |
# File 'lib/mainframe/host_base.rb', line 82 def exec_command cmd puts "Command: #{cmd}" if @debug sub_exec_command cmd wait_session end |
#get_cursor_axes ⇒ Object
Return the coordinates of the cursor
157 158 159 |
# File 'lib/mainframe/host_base.rb', line 157 def get_cursor_axes sub_get_cursor_axes end |
#quit ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mainframe/host_base.rb', line 51 def quit puts "Closing session with criterion \"#{@close_session}\"" if @debug case @close_session when :always, :yes sub_close_session puts "Session closed" if @debug wait_session 0.1 when :never, :no if @pid puts "Session forced to stay open" if @debug else puts "Session not closed because it was already existing anyway it would not been closed" if @debug end when :evaluate if @pid sub_close_session puts "Session closed because started by this process with id #{@pid}" if @debug wait_session 0.1 else puts "Session not closed because it was already existing" if @debug end end end |
#scan(options = {}) ⇒ Object
It reads one line or an area on the screen according to parameters supplied
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mainframe/host_base.rb', line 89 def scan ={} = { :y => nil, :x => nil, :len => nil, :y1 => nil, :x1 => nil, :y2 => nil, :x2 => nil, }.merge() if [:len] scan_row [:y], [:x], [:len] else scan_area [:y1], [:x1], [:y2], [:x2] end end |
#scan_page ⇒ Object
Scans and returns the text of the entire page
102 103 104 |
# File 'lib/mainframe/host_base.rb', line 102 def scan_page scan_area 1, 1, MAX_TERMINAL_ROWS, MAX_TERMINAL_COLUMNS end |
#set_cursor_axes(y, x, options = {}) ⇒ Object
Move the cursor at given coordinates
162 163 164 |
# File 'lib/mainframe/host_base.rb', line 162 def set_cursor_axes y, x, ={} sub_set_cursor_axes y, x, end |
#wait_session(wait = nil) ⇒ Object
Sleep time between operations
77 78 79 |
# File 'lib/mainframe/host_base.rb', line 77 def wait_session wait=nil sleep(wait || (@debug ? @wait_debug : @wait)) end |
#write(text, options = {}) ⇒ Object
Write text on screen at the coordinates Based on the parameters provided it writes a line or an area Options:
:hook => nil,
:y => nil, #row
:x => nil, #column
:check => true,
:raise_error_on_check => true,
:sensible_data => nil,
:clean_chars_before_writing => nil, # clean x chars before writing a value
:erase_before_writing => nil # execute an erase until end of field before write a text
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/mainframe/host_base.rb', line 117 def write text, ={} = show_deprecated_param(:erase_field_first, :erase_before_writing, ) if [:erase_field_first] = show_deprecated_param(:clean_first_chars, :clean_chars_before_writing, ) if [:clean_first_chars] = { :hook => nil, :y => nil, :x => nil, :check => true, :raise_error_on_check => true, :sensible_data => nil, :clean_chars_before_writing => nil, :erase_before_writing => @erase_before_writing }.merge() y = [:y] x = [:x] y ||= get_cursor_axes[0] x ||= get_cursor_axes[1] hooked_rows = 2 raise "Missing coordinates! y(row)=#{y} x(column)=#{x} " unless x && y raise "Sorry, cannot write null values at y=#{y} x=#{x}" unless text bol_written = false if [:hook] (y-hooked_rows..y+hooked_rows).each do |row_number| if /#{options[:hook]}/ === scan_row(row_number, 1, MAX_TERMINAL_COLUMNS) puts "Change y from #{y} to #{row_number} cause hook to:#{options[:hook]}" if row_number != y && @debug bol_written = write_text_on_map text, row_number, x, break end end else #If no control is required or was not found the label reference bol_written = write_text_on_map(text, y, x, ) unless bol_written end bol_written end |