DataMgr 0.1.1.1.pre → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/DataMgr.gemspec +0 -1
- data/README.md +24 -2
- data/lib/DataMgr/DB/db.rb +23 -94
- data/lib/DataMgr/DSL/dsl.rb +70 -0
- data/lib/DataMgr/Model/data_model.rb +50 -40
- data/lib/DataMgr/version.rb +1 -1
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2854606538cea24237e00b8ee35155cb3dcdc977
|
4
|
+
data.tar.gz: 6c379a4ddb9a6e77953866dfd5d2408763279a26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d0c3f600915c9ad34e2d656b7e43795dd9913069691b4b3f2cc6ef889fb89aeb292169a986c7e8f6cb4aae3fdf5f9b065d62ad7cad06e10e89ec4b2f23b401f
|
7
|
+
data.tar.gz: 74eeb52a6d38e76d383dfe26a476f60e4493b65094d101817a9b4178503edf30b7eff18128271cb740e9ce643b076fa0c1f191cc7fc2cac531431a897937f4cb
|
data/.gitignore
CHANGED
data/DataMgr.gemspec
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
# DataMgr
|
2
2
|
|
3
|
-
|
3
|
+
Data manager that provides support for JSON, YAML, and Database (e.g .SQL Server) dataware. Provides
|
4
|
+
the ability to manage the state of your data - creation, retrieve, and execute (SQL), then manage
|
5
|
+
those results for re-use later .. in your automation framework, app. code, etc.
|
6
|
+
|
7
|
+
Put your Ruby code in the file `lib/DataMgr`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
8
|
|
5
9
|
|
6
10
|
## Installation
|
7
11
|
|
12
|
+
### Prerequisite
|
13
|
+
|
14
|
+
http://stackoverflow.com/questions/33102569/installing-tiny-tds-gives-error-on-on-mac-os-10-10-5
|
15
|
+
|
8
16
|
Add this line to your application's Gemfile:
|
9
17
|
|
10
18
|
```ruby
|
@@ -21,7 +29,21 @@ Or install it yourself as:
|
|
21
29
|
|
22
30
|
## Usage
|
23
31
|
|
24
|
-
|
32
|
+
### Creating a connection configuration YAML file
|
33
|
+
|
34
|
+
MyConnectID:
|
35
|
+
user: sasquatch
|
36
|
+
password: kale
|
37
|
+
host: somewhere-in-the-woods.com
|
38
|
+
port: 2080
|
39
|
+
description: Big Foot
|
40
|
+
---
|
41
|
+
AnotherConnectID:
|
42
|
+
user: bigbird
|
43
|
+
password: yellow
|
44
|
+
host: sesame-street
|
45
|
+
port: 2080
|
46
|
+
description: Sesame Street Gang
|
25
47
|
|
26
48
|
## Development
|
27
49
|
|
data/lib/DataMgr/DB/db.rb
CHANGED
@@ -4,105 +4,35 @@
|
|
4
4
|
#
|
5
5
|
require 'singleton'
|
6
6
|
require 'yaml'
|
7
|
-
require 'tiny_tds'
|
8
7
|
|
9
8
|
module DataMgr
|
10
9
|
|
10
|
+
class DBConnectionError < StandardError
|
11
|
+
def initialize(msg="Connect - Unsupported. Install pre-release for DB support (e.g. gem install DataMgr --pre)")
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
11
16
|
class DB
|
12
17
|
include Singleton
|
13
18
|
|
14
19
|
attr_accessor :clients
|
15
20
|
attr_accessor :config
|
16
|
-
attr_accessor :debug
|
17
21
|
|
18
22
|
def initialize
|
19
23
|
@clients={}
|
20
|
-
@debug=false
|
21
24
|
end
|
22
25
|
|
23
26
|
def close(_id)
|
24
|
-
|
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
|
27
|
+
disconnect(_id)
|
91
28
|
end
|
92
29
|
|
93
30
|
def disconnect(_id)
|
94
31
|
rc=false
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
rc=true
|
99
|
-
end
|
100
|
-
rescue => ex
|
101
|
-
puts "Exception: #{ex.class}"
|
102
|
-
puts ex.backtrace
|
32
|
+
if @clients.has_key?(_id)
|
33
|
+
@clients[_id].close
|
34
|
+
rc=true
|
103
35
|
end
|
104
|
-
|
105
|
-
puts "disconnect(#{_id}): #{rc}" if @debug
|
106
36
|
rc
|
107
37
|
end
|
108
38
|
|
@@ -110,40 +40,40 @@ module DataMgr
|
|
110
40
|
def connect(_id)
|
111
41
|
rc=false
|
112
42
|
begin
|
113
|
-
conn=
|
43
|
+
conn=get(_id)
|
114
44
|
|
115
45
|
if !conn.nil?
|
116
46
|
|
117
|
-
|
47
|
+
raise DBConnectionError
|
118
48
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
rc
|
49
|
+
#@clients[_id] = TinyTds::Client.new username: conn['user'],
|
50
|
+
# password: conn['password'],
|
51
|
+
# host: conn['host'],
|
52
|
+
# port: conn['port']
|
53
|
+
#rc=true if @clients[_id].active?
|
124
54
|
else
|
125
55
|
puts __FILE__ + (__LINE__).to_s + " WARN: client #{_id} is not defined."
|
126
56
|
end
|
127
57
|
|
58
|
+
rescue DBConnectionError => ex
|
59
|
+
raise ex
|
60
|
+
|
128
61
|
rescue => ex
|
129
62
|
;
|
130
63
|
end
|
131
64
|
|
132
|
-
puts "connect(#{_id}) : #{rc}" if @debug
|
133
65
|
rc
|
134
66
|
end
|
135
67
|
|
136
68
|
|
137
|
-
def
|
69
|
+
def get(_id)
|
138
70
|
@config.each do |_c|
|
71
|
+
puts __FILE__ + (__LINE__).to_s + " get => #{_c}"
|
139
72
|
if _c.has_key?(_id)
|
140
|
-
puts __FILE__ + (__LINE__).to_s + " get(#{_id}) => #{_c[_id]}" if @debug
|
141
73
|
return _c[_id]
|
142
74
|
end
|
143
75
|
end
|
144
76
|
|
145
|
-
puts "get(#{_id}) => not found. (nil)"
|
146
|
-
|
147
77
|
nil
|
148
78
|
end
|
149
79
|
|
@@ -157,10 +87,9 @@ module DataMgr
|
|
157
87
|
puts __FILE__ + (__LINE__).to_s + " #{ex.class}: Invalid file: #{_config} - abort processing."
|
158
88
|
puts ex.backtrace
|
159
89
|
end
|
160
|
-
|
161
|
-
puts "load(#{_config}): #{rc}" if @debug
|
162
90
|
rc
|
163
91
|
end
|
92
|
+
|
164
93
|
end
|
165
94
|
|
166
95
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module DataMgr
|
5
|
+
|
6
|
+
class DSL
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
# Ex. './spec/fixtures/connect.yml'
|
15
|
+
def loadDB(_f)
|
16
|
+
DataMgr::DB.instance.load(_f)
|
17
|
+
end
|
18
|
+
|
19
|
+
def cmd(opts)
|
20
|
+
# puts "cmd => #{opts}"
|
21
|
+
rc=false
|
22
|
+
_cmd=nil
|
23
|
+
|
24
|
+
if opts.has_key?(:cmd)
|
25
|
+
_cmd=opts[:cmd]
|
26
|
+
else
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
|
30
|
+
if _cmd.match(/^\s*loaddb\s*\(.*\)\s*$/i)
|
31
|
+
dbName = _cmd.match(/^\s*loaddb\s*\((.*)\)\s*$/i)[1].to_s
|
32
|
+
rc=DataMgr::DB.instance.load(dbName)
|
33
|
+
|
34
|
+
elsif opts.has_key?(:cmd) && opts[:cmd].match(/^\s*connect\s*\((.*)\)\s*$/)
|
35
|
+
_connectID = opts[:cmd].match(/^\s*connect\s*\((.*)\)\s*$/i)[1].to_s
|
36
|
+
rc=DataMgr::DB.instance.connect(_connectID)
|
37
|
+
|
38
|
+
elsif _cmd.match(/^\s*getDB\s*\(.*\)\.get\(.*\)\s*$/)
|
39
|
+
db = _cmd.match(/^\s*getDB\s*\(\s*(.*)\s*\)\.get\(.*\)\s*$/)[1].to_s
|
40
|
+
# puts "db => #{db}"
|
41
|
+
# rc = queries.getDataElement(hit)
|
42
|
+
else
|
43
|
+
STDERR.puts " Unknown command: #{opts}"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
rc
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def connect(id)
|
52
|
+
DataMgr::DB.instance.connect(id)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def loadData(_f)
|
57
|
+
DataMgr::DataModel.new(_f)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
end
|
@@ -5,8 +5,10 @@ module DataMgr
|
|
5
5
|
class DataModel
|
6
6
|
attr_accessor :_file
|
7
7
|
attr_accessor :app_model
|
8
|
+
attr_accessor :debug
|
8
9
|
|
9
10
|
def initialize(f=nil)
|
11
|
+
@debug=false
|
10
12
|
|
11
13
|
if !f.nil?
|
12
14
|
@_file=f
|
@@ -20,13 +22,26 @@ module DataMgr
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def saveAs(_fname, _json)
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
rc=false
|
26
|
+
begin
|
27
|
+
_f=File.open(_fname, 'w')
|
28
|
+
_f.puts _json.to_json
|
29
|
+
_f.close
|
30
|
+
rc=true
|
31
|
+
|
32
|
+
rescue => ex
|
33
|
+
;
|
34
|
+
end
|
35
|
+
rc
|
26
36
|
end
|
27
37
|
|
38
|
+
|
28
39
|
def loadPages(jlist)
|
29
40
|
|
41
|
+
if jlist.nil? || jlist.empty?
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
30
45
|
json_list=[]
|
31
46
|
if jlist.kind_of?(String)
|
32
47
|
json_list << jlist
|
@@ -36,25 +51,44 @@ module DataMgr
|
|
36
51
|
|
37
52
|
jsonData={}
|
38
53
|
json_list.each { |f|
|
39
|
-
puts __FILE__ + (__LINE__).to_s + " JSON.parse(#{f})"
|
40
54
|
|
41
55
|
begin
|
42
|
-
|
43
|
-
|
56
|
+
|
57
|
+
_fd=nil
|
58
|
+
_contents=nil
|
59
|
+
_ext=File.extname(f)
|
60
|
+
|
61
|
+
if _ext.match(/\.(yaml|yml|json|jsn)\s*$/i)
|
62
|
+
_fd = File.open(f, 'r')
|
63
|
+
_contents=_fd.read
|
64
|
+
_fd.close
|
65
|
+
|
66
|
+
_contents = JSON.dump(YAML::load(_contents)) if _ext.match(/(yaml|yml)/i)
|
67
|
+
|
68
|
+
if !_contents.nil?
|
69
|
+
data_hash = JSON.parse _contents
|
70
|
+
jsonData.merge!(data_hash)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
44
75
|
rescue JSON::ParserError
|
45
|
-
|
76
|
+
STDERR.puts " raise JSON::ParseError - #{f.to_s}"
|
46
77
|
raise "JSONLoadError"
|
78
|
+
|
79
|
+
rescue => ex
|
80
|
+
STDERR.puts " Exception: #{ex.class}"
|
47
81
|
end
|
48
82
|
|
49
83
|
}
|
50
|
-
puts "merged jsonData => " + jsonData.to_json
|
84
|
+
puts "merged jsonData => " + jsonData.to_json if @debug
|
51
85
|
@app_model = jsonData
|
52
86
|
end
|
53
87
|
|
54
88
|
|
55
89
|
# getDataElement("data(address).get(city).get(zip)")
|
56
90
|
def getDataElement(s)
|
57
|
-
puts __FILE__ + (__LINE__).to_s + " getDataElement(#{s})"
|
91
|
+
puts __FILE__ + (__LINE__).to_s + " getDataElement(#{s})" if @debug
|
58
92
|
|
59
93
|
hit=@app_model
|
60
94
|
|
@@ -66,18 +100,18 @@ module DataMgr
|
|
66
100
|
getter = elt.split(/\(/)[0]
|
67
101
|
_obj = elt.match(/\((.*)\)/)[1]
|
68
102
|
|
69
|
-
puts __FILE__ + (__LINE__).to_s + " getter : #{getter} obj: #{_obj}"
|
103
|
+
puts __FILE__ + (__LINE__).to_s + " getter : #{getter} obj: #{_obj}" if @debug
|
70
104
|
|
71
105
|
if getter.downcase.match(/^\s*(getData)\s*/i)
|
72
|
-
puts __FILE__ + (__LINE__).to_s + " -- process page --"
|
106
|
+
puts __FILE__ + (__LINE__).to_s + " -- process page --" if @debug
|
73
107
|
hit=@app_model[_obj]
|
74
108
|
elsif getter.downcase=='get'
|
75
109
|
hit=hit[_obj]
|
76
110
|
else
|
77
|
-
puts __FILE__ + (__LINE__).to_s + " getter : #{getter} is unknown."
|
111
|
+
puts __FILE__ + (__LINE__).to_s + " getter : #{getter} is unknown." if @debug
|
78
112
|
return nil
|
79
113
|
end
|
80
|
-
puts __FILE__ + (__LINE__).to_s + " HIT => #{hit}"
|
114
|
+
puts __FILE__ + (__LINE__).to_s + " HIT => #{hit}" if @debug
|
81
115
|
}
|
82
116
|
|
83
117
|
hit
|
@@ -93,20 +127,13 @@ module DataMgr
|
|
93
127
|
if h.is_a?(Hash)
|
94
128
|
|
95
129
|
h.each do |k, v|
|
96
|
-
puts __FILE__ + (__LINE__).to_s + " Key: #{k} => #{v}"
|
130
|
+
puts __FILE__ + (__LINE__).to_s + " Key: #{k} => #{v}" if @debug
|
97
131
|
if k == condition
|
98
|
-
|
132
|
+
|
99
133
|
if !v.is_a?(Array) && v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)
|
100
134
|
|
101
135
|
dataObject=v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
|
102
136
|
|
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
137
|
if pg.nil?
|
111
138
|
result << parent
|
112
139
|
elsif pg == dataObject
|
@@ -117,15 +144,11 @@ module DataMgr
|
|
117
144
|
elsif v.is_a?(Array)
|
118
145
|
|
119
146
|
v.each do |vh|
|
120
|
-
puts " =====> #{vh}"
|
121
147
|
|
122
148
|
if vh.is_a?(Hash) && vh.has_key?(condition) && vh[condition].match(/^\s*#{_action}\s*/i)
|
123
149
|
|
124
150
|
pageObject=vh[condition].match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
|
125
151
|
|
126
|
-
|
127
|
-
puts __FILE__ + (__LINE__).to_s + " matched on #{_action}, pg:#{pg}, #{pageObject}"
|
128
|
-
|
129
152
|
if pg.nil?
|
130
153
|
result << parent
|
131
154
|
elsif pg == pageObject
|
@@ -145,33 +168,20 @@ module DataMgr
|
|
145
168
|
_rc = hits("#{parent}.get(#{k})", h[k], condition, _action, pg)
|
146
169
|
end
|
147
170
|
|
148
|
-
|
149
171
|
if !(_rc.nil? || _rc.empty?)
|
150
|
-
|
151
|
-
|
152
172
|
result << _rc
|
153
|
-
|
154
|
-
puts __FILE__ + (__LINE__).to_s + " ADDING #{k} : #{_rc}"
|
155
|
-
# puts "====> #{k} : #{_rc.class} : #{_rc.length}"
|
156
|
-
|
157
|
-
|
158
173
|
result.flatten!
|
159
174
|
end
|
160
|
-
|
161
|
-
|
162
175
|
end
|
163
176
|
end
|
164
177
|
|
165
178
|
end
|
166
179
|
|
167
|
-
|
168
180
|
result=nil if result.empty?
|
169
|
-
puts __FILE__ + (__LINE__).to_s + " result : #{result}"
|
181
|
+
puts __FILE__ + (__LINE__).to_s + " result : #{result}" if @debug
|
170
182
|
result
|
171
183
|
end
|
172
184
|
|
173
|
-
|
174
|
-
|
175
185
|
end
|
176
186
|
|
177
187
|
|
data/lib/DataMgr/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2016-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
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'
|
83
69
|
description: Manage dynamic data used for test input and output management.
|
84
70
|
email:
|
85
71
|
- h20dragon@outlook.com
|
@@ -90,7 +76,6 @@ files:
|
|
90
76
|
- ".gitignore"
|
91
77
|
- ".idea/DataMgr.iml"
|
92
78
|
- ".idea/encodings.xml"
|
93
|
-
- ".idea/vagrant.xml"
|
94
79
|
- ".rspec"
|
95
80
|
- ".travis.yml"
|
96
81
|
- CODE_OF_CONDUCT.md
|
@@ -103,6 +88,7 @@ files:
|
|
103
88
|
- bin/setup
|
104
89
|
- lib/DataMgr.rb
|
105
90
|
- lib/DataMgr/DB/db.rb
|
91
|
+
- lib/DataMgr/DSL/dsl.rb
|
106
92
|
- lib/DataMgr/Model/data_model.rb
|
107
93
|
- lib/DataMgr/version.rb
|
108
94
|
homepage: https://github.com/h20dragon
|
@@ -120,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
106
|
version: '0'
|
121
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
108
|
requirements:
|
123
|
-
- - "
|
109
|
+
- - ">="
|
124
110
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
111
|
+
version: '0'
|
126
112
|
requirements: []
|
127
113
|
rubyforge_project:
|
128
114
|
rubygems_version: 2.6.2
|