auto_data 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -34
- data/lib/auto_data.rb +49 -64
- data/lib/auto_data/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a50c6d8d43b6b127513a5dacc9f7bcbf05d81343
|
4
|
+
data.tar.gz: d3d7c54eb6dd93bbf44a0279cac61c49c0f2228e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 367d633923a6f4ba130262f18f9ef78651089fedc7a00d5ac64db723f6af1e8d4bc54ddd4a2a35ce759fe2d05b7b8d22f2343ba9c47028517ed03a84908cdbb9
|
7
|
+
data.tar.gz: e06aef3429131827f783633438a229ac65689466ee9b920254ca430442528a61030dbe89aee2a43965e07d05491049227fd64ddfe9936c3f280ae7aee522515d
|
data/README.md
CHANGED
@@ -22,50 +22,39 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
YML files are needed to define data.
|
24
24
|
|
25
|
-
|
26
|
-
CONF_ENV_TEST : key section to use from YML file for environment data
|
25
|
+
<b>AUTO_DATA_PATH</b> : Configuration data file path
|
27
26
|
|
27
|
+
if you are working with cucumber include the next line to <b>env.rb</b> file
|
28
28
|
```ruby
|
29
|
-
|
30
|
-
#Define global key variables
|
31
|
-
ENV["CONF_DATA_TEST"] = "manager"
|
32
|
-
ENV["CONF_ENV_TEST"] = "testing"
|
33
|
-
|
34
|
-
#Create objects
|
35
|
-
login=AutoData::Data.new
|
36
|
-
env = AutoData::Env.new
|
37
|
-
|
38
|
-
#Set path file that contains value details
|
39
|
-
login.load('config/data/users.yml')
|
40
|
-
env.load('config/data/environment.yml')
|
41
|
-
|
42
|
-
#Use the information as you have defined in the yml conf file
|
43
|
-
puts login.login #=> manager_id
|
44
|
-
puts login.password #=> zaq12wsx
|
45
|
-
puts login.username #=> Batman
|
46
|
-
|
47
|
-
#environment
|
48
|
-
puts env.base_url #=> http://testing.sample.com
|
49
|
-
|
29
|
+
ENV["AUTO_DATA_PATH"] = File.absolute_path('../..', File.dirname(__FILE__)).to_s
|
50
30
|
```
|
31
|
+
if not use using cucumber, place to the variable the project root path in your ruby class
|
32
|
+
```ruby
|
33
|
+
ENV["AUTO_DATA_PATH"] = <<YML path files>>
|
34
|
+
```
|
35
|
+
### Sample
|
36
|
+
```ruby
|
37
|
+
|
38
|
+
require 'auto_data'
|
39
|
+
#Set configuration file path (Assumming that class is under root folder)
|
51
40
|
|
52
|
-
|
41
|
+
ENV["AUTO_DATA_PATH"] = File.dirname(__FILE__)
|
53
42
|
|
54
|
-
|
43
|
+
#Create AutoData object
|
44
|
+
autodata = AutoData::Parse.new
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
|
46
|
+
#Print values format:objectname.filename('key.subkey')
|
47
|
+
#Users file
|
48
|
+
puts test.users('mananger.login') #=> manager_id
|
49
|
+
puts test.users('mananger.password') #=> zaq12wsx
|
50
|
+
puts test.users('mananger.username') #=> Batman
|
59
51
|
|
60
|
-
#
|
61
|
-
puts
|
62
|
-
puts login.password #=> zaq12wsx
|
63
|
-
puts login.username #=> Robin
|
52
|
+
#Environment file
|
53
|
+
puts test.environment('testing.base_url') #=> http://testing.sample.com
|
64
54
|
|
65
|
-
#environment
|
66
|
-
puts env.base_url #=> http://uat.sample.com
|
67
55
|
|
68
56
|
```
|
57
|
+
|
69
58
|
## Contributing
|
70
59
|
|
71
60
|
Bug reports and pull requests are welcome on GitHub at https://github.com/alekxaguilar/auto_data/issues. 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.
|
data/lib/auto_data.rb
CHANGED
@@ -1,83 +1,68 @@
|
|
1
1
|
require "auto_data/version"
|
2
2
|
require "yaml"
|
3
3
|
module AutoData
|
4
|
-
class Data
|
5
4
|
|
6
|
-
def initialize()
|
7
|
-
@data=ENV['CONF_DATA_TEST'].to_s.downcase
|
8
|
-
end
|
9
|
-
|
10
|
-
def load(file)
|
11
|
-
#@file = YAML.load_file(file)
|
12
|
-
|
13
|
-
@file = begin
|
14
|
-
YAML.load(File.open(file))
|
15
|
-
rescue Exception => e #ArgumentError
|
16
|
-
puts "Could not parse auto objects files: #{e.message}"
|
17
|
-
raise Exception.new('Could not parse auto objects files: #{e.message}')
|
18
|
-
end
|
19
|
-
#self
|
20
|
-
end
|
21
|
-
#Change environment key path
|
22
|
-
def change_scope(data)
|
23
|
-
@data=data.to_s.downcase
|
24
|
-
end
|
25
|
-
|
26
|
-
#Change data key path
|
27
|
-
def chage_scope(data_key)
|
28
|
-
@data=data_key.to_s.downcase
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def method_missing (method)
|
33
5
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
6
|
+
class Parse
|
7
|
+
#TODO: Make all methods private
|
8
|
+
def initialize()
|
9
|
+
@gvar=ENV['AUTO_DATA_PATH'].to_s
|
38
10
|
|
39
|
-
|
11
|
+
if @gvar.length == 0
|
12
|
+
raise Exception.new("Variable is not defined : ENV[\'AUTO_DATA_PATH\']")
|
40
13
|
end
|
14
|
+
|
15
|
+
@files = Hash.new
|
16
|
+
@file_count=0
|
41
17
|
|
42
|
-
|
43
|
-
|
18
|
+
Dir[ @gvar + '/**/*.yml'].each { |file| begin
|
19
|
+
@files['fullpath_' + @file_count.to_s]=file
|
20
|
+
@files['filename_' + @file_count.to_s]=file.split('/').last
|
21
|
+
@files['name_' + @file_count.to_s]=file.split('/').last.to_s.split('.').first
|
22
|
+
@file_count +=1
|
23
|
+
end}
|
44
24
|
|
45
|
-
end
|
46
25
|
|
47
|
-
|
26
|
+
end
|
48
27
|
|
49
|
-
|
50
|
-
|
51
|
-
def initialize()
|
52
|
-
@env = ENV['CONF_ENV_TEST'].to_s.downcase
|
53
|
-
end
|
28
|
+
def load(file)
|
54
29
|
|
55
|
-
|
56
|
-
|
57
|
-
@file = begin
|
58
|
-
YAML.load(File.open(file))
|
59
|
-
rescue Exception => e #ArgumentError
|
60
|
-
puts "Could not parse auto objects files: #{e.message}"
|
61
|
-
e.exception('adsfasdfas')
|
62
|
-
end
|
63
|
-
#self
|
30
|
+
if @files.value?(file).nil?
|
31
|
+
raise Exception.new("File name is not found #{file}")
|
64
32
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
rescue NoMethodError => e
|
73
|
-
puts "valdio dick #{e.message}"
|
33
|
+
key_value= @files.key(file.to_s).to_s
|
34
|
+
key_2find = 'fullpath_' + key_value.split('_').last
|
35
|
+
local_file_path =nil
|
36
|
+
@files.each_pair {|key,value| begin
|
37
|
+
if key == key_2find
|
38
|
+
local_file_path = value
|
39
|
+
break
|
74
40
|
end
|
75
|
-
|
41
|
+
end}
|
42
|
+
|
43
|
+
@file = begin
|
44
|
+
YAML.load_file(local_file_path)
|
45
|
+
rescue Exception => e
|
46
|
+
puts "Could not parse auto objects files: #{e.message}"
|
47
|
+
raise Exception.new('Could not parse auto objects files: #{e.message}')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing (filename, *args)
|
52
|
+
fileinfo= args[0].to_s.split('.')
|
53
|
+
if fileinfo.size !=2
|
54
|
+
raise Exception.new('Malformed structure, must be <AutoData.filename(\'key.subkey\')> ')
|
55
|
+
end
|
56
|
+
key= fileinfo[0]
|
57
|
+
subkey= fileinfo[1]
|
58
|
+
load(filename)
|
59
|
+
result= begin @file["#{key}"]["#{subkey}"].nil? ? 'No Value Found' : @file["#{key}"]["#{subkey}"]
|
60
|
+
rescue NoMethodError => e
|
61
|
+
puts "Couldn't find key #{subkey}.#{subkey} #{e.message}"
|
76
62
|
end
|
77
63
|
|
78
|
-
|
79
|
-
|
64
|
+
result
|
65
|
+
end
|
80
66
|
|
81
|
-
end
|
82
67
|
end
|
83
68
|
end
|
data/lib/auto_data/version.rb
CHANGED