iit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/iit.rb +82 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6986e645a79b22c09819f1944e73d52b6cf610a
4
+ data.tar.gz: 550574a3f181b4592b0b115a8bd0273a404e998f
5
+ SHA512:
6
+ metadata.gz: d2f633f69a79e96f959588421c647389e01cb46e34e95211518c58a52c8b9303aae5f54d95dc3daa630fddca2e3131cf541e5ecef6d7764a331fea357fb36656
7
+ data.tar.gz: c138da507c9a422db45aea87503c381f65ea6a65fe6dbac03b131b73ee7f1ec7473aecae88e06666d828f0f79409a6e10e7f33ef36081e06e13a2b9ea6172e31
@@ -0,0 +1,82 @@
1
+ module IIT
2
+ extend self
3
+
4
+ def qcmdexc cmd
5
+ output = `/QOpenSys/usr/bin/system \"#{cmd}\" 2>&1`
6
+ end
7
+
8
+ def run_sql cmd
9
+ qcmdexc "CALL PGM(QZDFMDB2) PARM('#{cmd}')"
10
+ end
11
+
12
+ def sys cmd
13
+ system cmd
14
+ end
15
+
16
+ def which(cmd)
17
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
18
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
19
+ exts.each { |ext|
20
+ exe = File.join(path, "#{cmd}#{ext}")
21
+ return exe if File.executable? exe
22
+ }
23
+ end
24
+ return nil
25
+ end
26
+
27
+ def DSPOBJD(lib, obj, type)
28
+ lib ||= '*LIBL'
29
+ qcmdexc "DSPOBJD OBJ(#{lib}/#{obj}) OBJTYPE(#{type}) DETAIL(*FULL)"
30
+ end
31
+
32
+ def DSPFFD(lib, obj)
33
+ lib ||= '*LIBL'
34
+ qcmdexc "DSPFFD FILE(#{lib}/#{obj}) OUTPUT(*)"
35
+ end
36
+
37
+ def DSPFD(lib, obj, type)
38
+ lib ||= '*LIBL'
39
+ qcmdexc "DSPFD FILE(#{lib}/#{obj}) TYPE(#{type}) OUTPUT(*)"
40
+ end
41
+
42
+ def DSPDTAARA(lib, obj)
43
+ lib ||= '*LIBL'
44
+ result = qcmdexc "DSPDTAARA DTAARA(#{lib}/#{obj}) OUTPUT(*) OUTFMT(*CHAR)"
45
+ type = /.*TYPE(.*)\n/.match(result)[1].strip rescue ''
46
+ length = /.*LEN(.*)\n/.match(result)[1].strip rescue ''
47
+ text = /.*TEXT(.*)\n/.match(result)[1].strip rescue ''
48
+ value = /.*VALUE(.*)\n/.match(result)[1].strip rescue ''
49
+ {type: type, length: length, text: text, value: value} #returning a hash for simple access: DSPDTAARA(...)[:type]
50
+ end
51
+
52
+ def object_created_by(lib, obj, type)
53
+ result = DSPOBJD(lib, obj, type)
54
+ /.*Created by user . . . . . . . . . . :(.*)\n/.match(result)[1].strip
55
+ end
56
+
57
+ def object_attribute(lib, obj, type)
58
+ result = DSPOBJD(lib, obj, type)
59
+ /.*Attribute . . . . . :(.*)\n/.match(result)[1].strip
60
+ end
61
+
62
+ def srcpf?(lib, obj)
63
+ DSPFFD(lib.chomp('.LIB'), obj.chomp('.FILE')).scan(/SRCSEQ|SRCDAT|SRCDTA/).length == 3
64
+ end
65
+
66
+ def src_type(lib, srcpf, mbr)
67
+ result = DSPFD(lib.chomp('.LIB'), srcpf.chomp('.FILE'), '*MBRLIST')
68
+ /^(?=.*\s\s#{mbr.chomp('.MBR')}\s).{30}(.{7})/.match(result)[1].strip rescue ''
69
+ end
70
+
71
+ def lib_exists? lib
72
+ !(qcmdexc "CHKOBJ OBJ(#{lib}) OBJTYPE(*LIB)").include? "CPF9801"
73
+ end
74
+
75
+ def obj_exists? lib, obj, type
76
+ !(qcmdexc "CHKOBJ OBJ(#{lib}/#{obj}) OBJTYPE(#{type})").include? "CPF9801"
77
+ end
78
+
79
+ def user_exists? user_name
80
+ !(qcmdexc "CHKOBJ OBJ(#{user_name}) OBJTYPE(*USRPRF)").include? "CPF9801"
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Bartell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A collection of APIs used to more easily interact with IBM i from the
14
+ Ruby language.
15
+ email: team@litmis.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/iit.rb
21
+ homepage: https://bitbucket.org/litmis/iit
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.14
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: IBM i Toolkit for Ruby
45
+ test_files: []