Module: IIT

Extended by:
IIT
Included in:
IIT
Defined in:
lib/iit.rb

Instance Method Summary collapse

Instance Method Details

#DSPDTAARA(lib, obj) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/iit.rb', line 42

def DSPDTAARA(lib, obj)
  lib ||= '*LIBL'
  result = qcmdexc "DSPDTAARA DTAARA(#{lib}/#{obj}) OUTPUT(*) OUTFMT(*CHAR)"
  type   = /.*TYPE(.*)\n/.match(result)[1].strip rescue ''
  length = /.*LEN(.*)\n/.match(result)[1].strip rescue ''
  text   = /.*TEXT(.*)\n/.match(result)[1].strip rescue ''
  value  = /.*VALUE(.*)\n/.match(result)[1].strip rescue ''
  {type: type, length: length, text: text, value: value}  #returning a hash for simple access: DSPDTAARA(...)[:type]
end

#DSPFD(lib, obj, type) ⇒ Object



37
38
39
40
# File 'lib/iit.rb', line 37

def DSPFD(lib, obj, type)
  lib ||= '*LIBL'
  qcmdexc "DSPFD FILE(#{lib}/#{obj}) TYPE(#{type}) OUTPUT(*)"
end

#DSPFFD(lib, obj) ⇒ Object



32
33
34
35
# File 'lib/iit.rb', line 32

def DSPFFD(lib, obj)
  lib ||= '*LIBL'
  qcmdexc "DSPFFD FILE(#{lib}/#{obj}) OUTPUT(*)"
end

#DSPOBJD(lib, obj, type) ⇒ Object



27
28
29
30
# File 'lib/iit.rb', line 27

def DSPOBJD(lib, obj, type)
  lib ||= '*LIBL'
  qcmdexc "DSPOBJD OBJ(#{lib}/#{obj}) OBJTYPE(#{type}) DETAIL(*FULL)"
end

#lib_exists?(lib) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/iit.rb', line 71

def lib_exists? lib
  !(qcmdexc "CHKOBJ OBJ(#{lib}) OBJTYPE(*LIB)").include? "CPF9801"
end

#obj_exists?(lib, obj, type) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/iit.rb', line 75

def obj_exists? lib, obj, type
  !(qcmdexc "CHKOBJ OBJ(#{lib}/#{obj}) OBJTYPE(#{type})").include? "CPF9801"
end

#object_attribute(lib, obj, type) ⇒ Object



57
58
59
60
# File 'lib/iit.rb', line 57

def object_attribute(lib, obj, type)
  result = DSPOBJD(lib, obj, type)
  /.*Attribute  . . . . . :(.*)\n/.match(result)[1].strip
end

#object_created_by(lib, obj, type) ⇒ Object



52
53
54
55
# File 'lib/iit.rb', line 52

def object_created_by(lib, obj, type)
  result = DSPOBJD(lib, obj, type)
  /.*Created by user  . . . . . . . . . . :(.*)\n/.match(result)[1].strip
end

#qcmdexc(cmd) ⇒ Object



4
5
6
# File 'lib/iit.rb', line 4

def qcmdexc cmd
  output = `/QOpenSys/usr/bin/system \"#{cmd}\" 2>&1`
end

#run_sql(cmd) ⇒ Object



8
9
10
# File 'lib/iit.rb', line 8

def run_sql cmd
  qcmdexc "CALL PGM(QZDFMDB2) PARM('#{cmd}')"
end

#src_type(lib, srcpf, mbr) ⇒ Object



66
67
68
69
# File 'lib/iit.rb', line 66

def src_type(lib, srcpf, mbr)
  result = DSPFD(lib.chomp('.LIB'), srcpf.chomp('.FILE'), '*MBRLIST')  
  /^(?=.*\s\s#{mbr.chomp('.MBR')}\s).{30}(.{7})/.match(result)[1].strip rescue ''
end

#srcpf?(lib, obj) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/iit.rb', line 62

def srcpf?(lib, obj)
  DSPFFD(lib.chomp('.LIB'), obj.chomp('.FILE')).scan(/SRCSEQ|SRCDAT|SRCDTA/).length == 3
end

#sys(cmd) ⇒ Object



12
13
14
# File 'lib/iit.rb', line 12

def sys cmd
  system cmd
end

#user_exists?(user_name) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/iit.rb', line 79

def user_exists? user_name
  !(qcmdexc "CHKOBJ OBJ(#{user_name}) OBJTYPE(*USRPRF)").include? "CPF9801"
end

#which(cmd) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/iit.rb', line 16

def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable? exe
    }
  end
  return nil
end