DataMgr 0.1.0 → 0.1.1.1.pre

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86800734a387699c06d9574cbf1d2958f571e6b8
4
- data.tar.gz: f884ae5c4775c9c18a24733d1ebdb9e43388d65c
3
+ metadata.gz: 1dbac8cd85c6be82abd3eb4bdd123106217b1977
4
+ data.tar.gz: 75ed3af46d91f8cc1fcdf845f05656e74f1bd453
5
5
  SHA512:
6
- metadata.gz: 59bb69c787c40c3641f8223cad9e3fc3a0df110aea13d3c34f90a6774d76d150e1e254cc5820919c1ccb98354b20124060d7ba7a9e62738e5beeed8ce10e23fb
7
- data.tar.gz: 2ab830ea1aa4fc8db6426f0282381afe3439b37c7b3f0bafb12708fdd96c848ea2fe54334da7bb82c0d2e42e2dc5a11e2af4b6d04d6b20818d2d2a6451920eac
6
+ metadata.gz: d2f486c8859c5df8aa5c162428b2bdf964e4c2c0a08feea2855e80e0e138bb51c29e7439320ec43230b51ef2970f44d1a97797c537586657861b264a0fd37548
7
+ data.tar.gz: 13f0e524e024a22946f9acca7b7da8eb33a3a808081658a464f477de8fadb38cdd615f117ccaf0159daede94234a643a67c881116af805e1bd9b3c684b0ee0bf
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /.idea/
2
3
  /.yardoc
3
4
  /Gemfile.lock
4
5
  /_yardoc/
data/DataMgr.gemspec CHANGED
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.11"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "json", ">= 1.8.3"
34
+ spec.add_development_dependency "tiny_tds"
33
35
  end
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/DataMgr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
7
6
  ## Installation
8
7
 
@@ -32,7 +31,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
31
 
33
32
  ## Contributing
34
33
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/DataMgr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/h20dragon/DataMgr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
35
 
37
36
 
38
37
  ## License
@@ -0,0 +1,168 @@
1
+ #
2
+ # QA Engineering
3
+ # All Rights Reserved 2016
4
+ #
5
+ require 'singleton'
6
+ require 'yaml'
7
+ require 'tiny_tds'
8
+
9
+ module DataMgr
10
+
11
+ class DB
12
+ include Singleton
13
+
14
+ attr_accessor :clients
15
+ attr_accessor :config
16
+ attr_accessor :debug
17
+
18
+ def initialize
19
+ @clients={}
20
+ @debug=false
21
+ end
22
+
23
+ def close(_id)
24
+ rc=disconnect(_id)
25
+ puts "close(#{_id}): #{rc}" if @debug
26
+ rc
27
+ end
28
+
29
+ def _execute(c, q)
30
+
31
+ begin
32
+ if c.active?
33
+ puts "execute(#{q} ..." if @debug
34
+ rc=c.execute(q)
35
+
36
+ puts "rc : #{rc.class} : #{rc}"
37
+
38
+ h={}
39
+
40
+ if rc.is_a?(TinyTds::Result)
41
+ rc.each_with_index do |row, i|
42
+
43
+ h[i]=row
44
+
45
+ puts "#{i}. #{row.class} : #{row}" if @debug
46
+ end
47
+ end
48
+
49
+ rc=h.to_yaml
50
+ puts h.to_yaml
51
+ end
52
+ rescue => ex
53
+ ;
54
+ end
55
+
56
+ puts "_execute(c, #{q}): #{h}" if @debug
57
+ h
58
+ end
59
+
60
+
61
+ def run(_id, q)
62
+ rc=nil
63
+ puts "run(#{_id}, #{q})" if @debug
64
+
65
+ begin
66
+ if @clients.has_key?(_id)
67
+
68
+ if @clients[_id].active?
69
+ puts "=> active" if @debug
70
+
71
+ rc=_execute(@clients[_id], q)
72
+ else
73
+ puts "warning: connection #{_id} is not active." if @debug
74
+ end
75
+ else
76
+
77
+ puts "run(#{_id}, #{q}) : WARN - not connected."
78
+ _c = getConfig(_id)
79
+ if !_c.nil? && _c.connect(_id)
80
+ if _c.active?
81
+ rc=_execute(@clients[_id], q)
82
+ end
83
+ end
84
+
85
+ end
86
+ rescue => ex
87
+ puts "Exception: #{ex.class}"
88
+ puts ex.backtrace
89
+ end
90
+ rc
91
+ end
92
+
93
+ def disconnect(_id)
94
+ rc=false
95
+ begin
96
+ if @clients.has_key?(_id)
97
+ @clients[_id].close
98
+ rc=true
99
+ end
100
+ rescue => ex
101
+ puts "Exception: #{ex.class}"
102
+ puts ex.backtrace
103
+ end
104
+
105
+ puts "disconnect(#{_id}): #{rc}" if @debug
106
+ rc
107
+ end
108
+
109
+
110
+ def connect(_id)
111
+ rc=false
112
+ begin
113
+ conn=getConfig(_id)
114
+
115
+ if !conn.nil?
116
+
117
+ puts ".. connect(#{_id}) ..." if @debug
118
+
119
+ @clients[_id] = TinyTds::Client.new username: conn['user'],
120
+ password: conn['password'],
121
+ host: conn['host'],
122
+ port: conn['port']
123
+ rc=@clients[_id].active?
124
+ else
125
+ puts __FILE__ + (__LINE__).to_s + " WARN: client #{_id} is not defined."
126
+ end
127
+
128
+ rescue => ex
129
+ ;
130
+ end
131
+
132
+ puts "connect(#{_id}) : #{rc}" if @debug
133
+ rc
134
+ end
135
+
136
+
137
+ def getConfig(_id)
138
+ @config.each do |_c|
139
+ if _c.has_key?(_id)
140
+ puts __FILE__ + (__LINE__).to_s + " get(#{_id}) => #{_c[_id]}" if @debug
141
+ return _c[_id]
142
+ end
143
+ end
144
+
145
+ puts "get(#{_id}) => not found. (nil)"
146
+
147
+ nil
148
+ end
149
+
150
+
151
+ def load(_config)
152
+ rc=false
153
+ begin
154
+ @config=YAML.load_stream File.read(_config)
155
+ rc=true
156
+ rescue => ex
157
+ puts __FILE__ + (__LINE__).to_s + " #{ex.class}: Invalid file: #{_config} - abort processing."
158
+ puts ex.backtrace
159
+ end
160
+
161
+ puts "load(#{_config}): #{rc}" if @debug
162
+ rc
163
+ end
164
+ end
165
+
166
+
167
+
168
+ end
@@ -0,0 +1,179 @@
1
+ require 'json'
2
+
3
+ module DataMgr
4
+
5
+ class DataModel
6
+ attr_accessor :_file
7
+ attr_accessor :app_model
8
+
9
+ def initialize(f=nil)
10
+
11
+ if !f.nil?
12
+ @_file=f
13
+ loadPages(@_file)
14
+ end
15
+
16
+ end
17
+
18
+ def getAppModel()
19
+ @app_model
20
+ end
21
+
22
+ def saveAs(_fname, _json)
23
+ _f=File.open(_fname, 'w')
24
+ _f.puts _json.to_json
25
+ _f.close
26
+ end
27
+
28
+ def loadPages(jlist)
29
+
30
+ json_list=[]
31
+ if jlist.kind_of?(String)
32
+ json_list << jlist
33
+ else
34
+ json_list=jlist
35
+ end
36
+
37
+ jsonData={}
38
+ json_list.each { |f|
39
+ puts __FILE__ + (__LINE__).to_s + " JSON.parse(#{f})"
40
+
41
+ begin
42
+ data_hash = JSON.parse File.read(f)
43
+ jsonData.merge!(data_hash)
44
+ rescue JSON::ParserError
45
+ Scoutui::Logger::LogMgr.instance.fatal "raise JSON::ParseError - #{f.to_s}"
46
+ raise "JSONLoadError"
47
+ end
48
+
49
+ }
50
+ puts "merged jsonData => " + jsonData.to_json
51
+ @app_model = jsonData
52
+ end
53
+
54
+
55
+ # getDataElement("data(address).get(city).get(zip)")
56
+ def getDataElement(s)
57
+ puts __FILE__ + (__LINE__).to_s + " getDataElement(#{s})"
58
+
59
+ hit=@app_model
60
+
61
+ nodes = s.split(/\./)
62
+
63
+ nodes.each { |elt|
64
+
65
+ puts __FILE__ + (__LINE__).to_s + " process #{elt}"
66
+ getter = elt.split(/\(/)[0]
67
+ _obj = elt.match(/\((.*)\)/)[1]
68
+
69
+ puts __FILE__ + (__LINE__).to_s + " getter : #{getter} obj: #{_obj}"
70
+
71
+ if getter.downcase.match(/^\s*(getData)\s*/i)
72
+ puts __FILE__ + (__LINE__).to_s + " -- process page --"
73
+ hit=@app_model[_obj]
74
+ elsif getter.downcase=='get'
75
+ hit=hit[_obj]
76
+ else
77
+ puts __FILE__ + (__LINE__).to_s + " getter : #{getter} is unknown."
78
+ return nil
79
+ end
80
+ puts __FILE__ + (__LINE__).to_s + " HIT => #{hit}"
81
+ }
82
+
83
+ hit
84
+ end
85
+
86
+
87
+
88
+ def hits(parent, h, condition, _action, pg)
89
+ # puts __FILE__ + (__LINE__).to_s + " collect_item_attributes(#{h})"
90
+ result = []
91
+
92
+
93
+ if h.is_a?(Hash)
94
+
95
+ h.each do |k, v|
96
+ puts __FILE__ + (__LINE__).to_s + " Key: #{k} => #{v}"
97
+ if k == condition
98
+ # h[k].each {|k, v| result[k] = v } # <= tweak here
99
+ if !v.is_a?(Array) && v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)
100
+
101
+ dataObject=v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
102
+
103
+ puts __FILE__ + (__LINE__).to_s + " <pg, pageObject> : <#{pg}, #{dataObject}>"
104
+ # result[k] = v
105
+
106
+ # puts '*******************'
107
+ # puts __FILE__ + (__LINE__).to_s + " HIT : #{h[k]}"
108
+ # result << { h[k] => v }
109
+
110
+ if pg.nil?
111
+ result << parent
112
+ elsif pg == dataObject
113
+ result << parent
114
+
115
+ end
116
+
117
+ elsif v.is_a?(Array)
118
+
119
+ v.each do |vh|
120
+ puts " =====> #{vh}"
121
+
122
+ if vh.is_a?(Hash) && vh.has_key?(condition) && vh[condition].match(/^\s*#{_action}\s*/i)
123
+
124
+ pageObject=vh[condition].match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
125
+
126
+
127
+ puts __FILE__ + (__LINE__).to_s + " matched on #{_action}, pg:#{pg}, #{pageObject}"
128
+
129
+ if pg.nil?
130
+ result << parent
131
+ elsif pg == pageObject
132
+ result << parent
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+
141
+ elsif v.is_a? Hash
142
+ if parent.nil?
143
+ _rc = hits("page(#{k})", h[k], condition, _action, pg)
144
+ else
145
+ _rc = hits("#{parent}.get(#{k})", h[k], condition, _action, pg)
146
+ end
147
+
148
+
149
+ if !(_rc.nil? || _rc.empty?)
150
+
151
+
152
+ result << _rc
153
+
154
+ puts __FILE__ + (__LINE__).to_s + " ADDING #{k} : #{_rc}"
155
+ # puts "====> #{k} : #{_rc.class} : #{_rc.length}"
156
+
157
+
158
+ result.flatten!
159
+ end
160
+
161
+
162
+ end
163
+ end
164
+
165
+ end
166
+
167
+
168
+ result=nil if result.empty?
169
+ puts __FILE__ + (__LINE__).to_s + " result : #{result}"
170
+ result
171
+ end
172
+
173
+
174
+
175
+ end
176
+
177
+
178
+
179
+ end
@@ -1,3 +1,3 @@
1
1
  module DataMgr
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1.1.pre"
3
3
  end
data/lib/DataMgr.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "DataMgr/version"
2
2
 
3
3
  module DataMgr
4
- # Your code goes here...
4
+ ROOT_DIR = File.join(File.dirname(File.expand_path(__FILE__)), 'DataMgr').freeze
5
+
6
+ Dir["#{ROOT_DIR}/*.rb"].each { |f| require f }
7
+ Dir["#{ROOT_DIR}/**/*.rb"].each { |f| require f }
5
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DataMgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Kim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-25 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: tiny_tds
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Manage dynamic data used for test input and output management.
56
84
  email:
57
85
  - h20dragon@outlook.com
@@ -74,6 +102,8 @@ files:
74
102
  - bin/console
75
103
  - bin/setup
76
104
  - lib/DataMgr.rb
105
+ - lib/DataMgr/DB/db.rb
106
+ - lib/DataMgr/Model/data_model.rb
77
107
  - lib/DataMgr/version.rb
78
108
  homepage: https://github.com/h20dragon
79
109
  licenses:
@@ -90,9 +120,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
120
  version: '0'
91
121
  required_rubygems_version: !ruby/object:Gem::Requirement
92
122
  requirements:
93
- - - ">="
123
+ - - ">"
94
124
  - !ruby/object:Gem::Version
95
- version: '0'
125
+ version: 1.3.1
96
126
  requirements: []
97
127
  rubyforge_project:
98
128
  rubygems_version: 2.6.2