Class: Racf::Client
- Inherits:
-
Object
- Object
- Racf::Client
- Defined in:
- lib/racf/client.rb
Overview
That class is intended to be “the” API for clients of the RACF gem. You can use it to open a connection with a mainframe run some RACF commands and then close the connection.
Constant Summary collapse
- COMMANDS =
%w(listgrp listuser rlist search)
Instance Attribute Summary collapse
-
#caching ⇒ Object
Returns the value of attribute caching.
-
#password ⇒ Object
Returns the value of attribute password.
-
#script_port ⇒ Object
Returns the value of attribute script_port.
-
#server_address ⇒ Object
Returns the value of attribute server_address.
-
#server_port ⇒ Object
Returns the value of attribute server_port.
-
#session ⇒ Object
Returns the value of attribute session.
-
#telnet_timeout ⇒ Object
Returns the value of attribute telnet_timeout.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #cache ⇒ Object
- #cache=(serialized_cache) ⇒ Object
- #dump_cache ⇒ Object
- #finish_session ⇒ Object
-
#initialize(settings = {}) ⇒ Client
constructor
A new instance of Client.
- #load_cache ⇒ Object
-
#logger=(logger) ⇒ Object
we should deprecate this api, in favor to config it globally.
- #start_session ⇒ Object
Constructor Details
#initialize(settings = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/racf/client.rb', line 17 def initialize(settings={}) settings = Racf.config.merge(settings) @user_id = settings[:user_id] @password = settings[:password] @server_address = settings[:server_address] @server_port = settings[:server_port] @script_port = settings[:script_port] @telnet_timeout = settings[:telnet_timeout] @caching = settings[:caching].nil? ? true : settings[:caching] @verbose = settings[:verbose].nil? ? false : settings[:verbose] @session = settings[:session] || create_session load_pagers end |
Instance Attribute Details
#caching ⇒ Object
Returns the value of attribute caching.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def caching @caching end |
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def password @password end |
#script_port ⇒ Object
Returns the value of attribute script_port.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def script_port @script_port end |
#server_address ⇒ Object
Returns the value of attribute server_address.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def server_address @server_address end |
#server_port ⇒ Object
Returns the value of attribute server_port.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def server_port @server_port end |
#session ⇒ Object
Returns the value of attribute session.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def session @session end |
#telnet_timeout ⇒ Object
Returns the value of attribute telnet_timeout.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def telnet_timeout @telnet_timeout end |
#user_id ⇒ Object
Returns the value of attribute user_id.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def user_id @user_id end |
#verbose ⇒ Object
Returns the value of attribute verbose.
14 15 16 |
# File 'lib/racf/client.rb', line 14 def verbose @verbose end |
Instance Method Details
#cache ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/racf/client.rb', line 90 def cache cache_dump = {} @pagers.each do |command_class, pager| if pager.respond_to? :cache cache_dump[command_class.to_s] = pager.cache end end cache_dump end |
#cache=(serialized_cache) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/racf/client.rb', line 82 def cache=(serialized_cache) @pagers.each do |command_class, pager| if pager.respond_to? :cache= pager.cache = serialized_cache[command_class.to_s] end end end |
#dump_cache ⇒ Object
72 73 74 |
# File 'lib/racf/client.rb', line 72 def dump_cache File.open(Racf.dump_file_path, "w") { |f| YAML.dump(cache, f) } end |
#finish_session ⇒ Object
50 51 52 |
# File 'lib/racf/client.rb', line 50 def finish_session session.finish end |
#load_cache ⇒ Object
76 77 78 79 80 |
# File 'lib/racf/client.rb', line 76 def load_cache self.cache = YAML.load_file(Racf.dump_file_path) rescue StandardError Racf.logger.warn "Could not load cache file! Running with empty cache." end |
#logger=(logger) ⇒ Object
we should deprecate this api, in favor to config it globally
55 56 57 |
# File 'lib/racf/client.rb', line 55 def logger=(logger) Racf.logger = logger end |
#start_session ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/racf/client.rb', line 34 def start_session session.start if block_given? begin yield self rescue Exception => exception Racf.logger.error exception. Racf.logger.error exception.backtrace.join("\n") raise ensure finish_session end end end |