auto_data 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +39 -0
- data/config/data/environment.yml +2 -0
- data/config/data/users.yml +4 -2
- data/lib/auto_data.rb +77 -40
- data/lib/auto_data/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fb87681d43992793e3d2a80c61b0062f6657371
|
4
|
+
data.tar.gz: 923cbc8ce0988d5e6350357952d266417fe9c6e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 978890b063d30f52fa263b45abd7207c7364078657e6de2bfcf919ea2341b5db8d97707a39f027ff679ee5c8ee77c520d13f667f9c1591a5c65658ec76d187f1
|
7
|
+
data.tar.gz: faa4c241f7c7ed5f5596ed7e863c44b208696b4423183ffa4262e7cb5538d5da386546bd91a6cd7e29c4e0125cb0768bffeebf3d97bebc879730344f07aa99d5
|
data/README.md
CHANGED
@@ -33,6 +33,19 @@ if not use using cucumber, place to the variable the project root path in your r
|
|
33
33
|
ENV["AUTO_DATA_PATH"] = <<YML path files>>
|
34
34
|
```
|
35
35
|
### Sample
|
36
|
+
YML's [sample data](https://github.com/alekxaguilar/auto_data/tree/master/config/data)
|
37
|
+
|
38
|
+
Optional YML file structure:
|
39
|
+
|
40
|
+
```yml
|
41
|
+
default_key: user_role2 #optional
|
42
|
+
|
43
|
+
user_role1:
|
44
|
+
userid: userid1
|
45
|
+
user_role2:
|
46
|
+
userid: userid2
|
47
|
+
```
|
48
|
+
Code using custom key and sub-key words
|
36
49
|
```ruby
|
37
50
|
|
38
51
|
require 'auto_data'
|
@@ -53,6 +66,32 @@ ENV["AUTO_DATA_PATH"] = <<YML path files>>
|
|
53
66
|
puts test.environment('testing.base_url') #=> http://testing.sample.com
|
54
67
|
|
55
68
|
|
69
|
+
```
|
70
|
+
Using custom default_key option
|
71
|
+
```ruby
|
72
|
+
|
73
|
+
#Create AutoData object
|
74
|
+
autodata = AutoData::Parse.new
|
75
|
+
|
76
|
+
#users.yml file must has default_key, i.e. 'default_key: manager'
|
77
|
+
puts test.users('login') #=> manager_id
|
78
|
+
puts test.users('password') #=> zaq12wsx1
|
79
|
+
puts test.users('username') #=> Batman
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```
|
84
|
+
Changing default_key from code
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
|
88
|
+
test.change_scope('users','customer')
|
89
|
+
|
90
|
+
#print again
|
91
|
+
puts test.users('login') #=> customer_id
|
92
|
+
puts test.users('password') #=> zaq12wsx2
|
93
|
+
puts test.users('username') #=> Robin
|
94
|
+
|
56
95
|
```
|
57
96
|
|
58
97
|
## Contributing
|
data/config/data/environment.yml
CHANGED
data/config/data/users.yml
CHANGED
data/lib/auto_data.rb
CHANGED
@@ -4,27 +4,84 @@ module AutoData
|
|
4
4
|
|
5
5
|
|
6
6
|
class Parse
|
7
|
-
#TODO:
|
7
|
+
#TODO: Change methods to private
|
8
8
|
def initialize()
|
9
9
|
@gvar=ENV['AUTO_DATA_PATH'].to_s
|
10
|
-
|
11
10
|
if @gvar.length == 0
|
12
11
|
raise Exception.new("Variable is not defined : ENV[\'AUTO_DATA_PATH\']")
|
13
12
|
end
|
14
|
-
|
15
13
|
@files = Hash.new
|
16
14
|
@file_count=0
|
15
|
+
Dir[@gvar + '/**/*.yml'].each { |file|
|
16
|
+
begin
|
17
|
+
@files['fullpath_' + @file_count.to_s]=file
|
18
|
+
@files['filename_' + @file_count.to_s]=file.split('/').last
|
19
|
+
@name_def_key =file.split('/').last.to_s.split('.').first
|
20
|
+
@files['name_' + @file_count.to_s]=@name_def_key #file.split('/').last.to_s.split('.').first
|
21
|
+
@info = begin
|
22
|
+
YAML.load_file(file)
|
23
|
+
rescue Exception => e
|
24
|
+
puts "Could not parse auto objects files: #{e.message}"
|
25
|
+
raise Exception.new('Could not parse auto objects files: #{e.message}')
|
26
|
+
end
|
27
|
+
@files["#{@name_def_key}_default_key"]= begin
|
28
|
+
@info["default_key"].nil? ? 'NotFound' : @info["default_key"]
|
29
|
+
rescue NoMethodError => e
|
30
|
+
puts "Couldn't find key #{default_key} - #{e.message}"
|
31
|
+
end
|
17
32
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@file_count +=1
|
23
|
-
end}
|
33
|
+
@file_count +=1
|
34
|
+
end }
|
35
|
+
# puts @files
|
36
|
+
end
|
24
37
|
|
38
|
+
def change_scope(filename, new_value)
|
39
|
+
if !@files.value?(filename)
|
40
|
+
raise Exception.new("File name '#{filename}' is not found")
|
41
|
+
else
|
42
|
+
@files["#{filename}_default_key"] = new_value
|
43
|
+
end
|
44
|
+
end #End change_scope
|
25
45
|
|
26
|
-
|
46
|
+
private
|
47
|
+
def method_missing (filename, *args)
|
48
|
+
use_default_key= false
|
49
|
+
if args[0].count('.') == 0 #use custom key; >0 usedefault_key
|
50
|
+
use_default_key=true
|
51
|
+
subkey=args[0].to_s
|
52
|
+
else
|
53
|
+
fileinfo= args[0].to_s.split('.')
|
54
|
+
if fileinfo.size !=2
|
55
|
+
raise Exception.new('Malformed structure, must be <AutoData.filename(\'key.subkey\')> ')
|
56
|
+
end
|
57
|
+
key= fileinfo[0]
|
58
|
+
subkey= fileinfo[1]
|
59
|
+
end
|
60
|
+
|
61
|
+
load(filename)
|
62
|
+
if use_default_key
|
63
|
+
if @files.key?(filename.to_s + '_default_key')
|
64
|
+
default_key = @files["#{filename}_default_key"]
|
65
|
+
else
|
66
|
+
raise Exception.new("Couldn't find key default_key. ")
|
67
|
+
end
|
68
|
+
result= begin
|
69
|
+
@file["#{default_key}"]["#{subkey}"].nil? ? 'No Value Found' : @file["#{default_key}"]["#{subkey}"]
|
70
|
+
rescue NoMethodError => e
|
71
|
+
puts "Couldn't find key #{subkey} using 'default_key' #{e.message}"
|
72
|
+
end
|
73
|
+
else
|
74
|
+
result= begin
|
75
|
+
@file["#{key}"]["#{subkey}"].nil? ? 'No Value Found' : @file["#{key}"]["#{subkey}"]
|
76
|
+
rescue NoMethodError => e
|
77
|
+
puts "Couldn't find key #{subkey}.#{subkey} #{e.message}"
|
78
|
+
end
|
79
|
+
end
|
27
80
|
|
81
|
+
result
|
82
|
+
end #End method_missing
|
83
|
+
|
84
|
+
private
|
28
85
|
def load(file)
|
29
86
|
|
30
87
|
if @files.value?(file).nil?
|
@@ -32,37 +89,17 @@ module AutoData
|
|
32
89
|
end
|
33
90
|
key_value= @files.key(file.to_s).to_s
|
34
91
|
key_2find = 'fullpath_' + key_value.split('_').last
|
35
|
-
local_file_path
|
36
|
-
@files.each_pair {|key,value| begin
|
37
|
-
if key == key_2find
|
38
|
-
local_file_path = value
|
39
|
-
break
|
40
|
-
end
|
41
|
-
end}
|
42
|
-
|
92
|
+
local_file_path= @files.values_at(key_2find)
|
43
93
|
@file = begin
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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}"
|
94
|
+
YAML.load_file(local_file_path[0].to_s)
|
95
|
+
rescue Exception => e
|
96
|
+
puts "Could not parse auto objects files: #{e.message}"
|
97
|
+
raise Exception.new('Could not parse auto objects files: #{e.message}')
|
62
98
|
end
|
99
|
+
end #end Load
|
100
|
+
|
101
|
+
|
102
|
+
end #End Parse Class
|
63
103
|
|
64
|
-
result
|
65
|
-
end
|
66
104
|
|
67
|
-
|
68
|
-
end
|
105
|
+
end #End Module
|
data/lib/auto_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Aguilar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|