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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f979d9a19f6b1e9dca7c8da1cc6dcab1fb5ae631
4
- data.tar.gz: c6bb8218cbf1cad7909a67128843b5601cc1823a
3
+ metadata.gz: a50c6d8d43b6b127513a5dacc9f7bcbf05d81343
4
+ data.tar.gz: d3d7c54eb6dd93bbf44a0279cac61c49c0f2228e
5
5
  SHA512:
6
- metadata.gz: c1315a87b6a77fc343f6739933d1ad91771526943c0f29a0350c734dffceac89020641fae4cc1d3661321a10fff27a03d6eb192c814a497c8418555ac0ee93e1
7
- data.tar.gz: e67012a0223c348cb8bf4d9f55ec12fe8581190d6bf8f3aef3398b60a4d79d5385cfcd1e1d39679a97ff55648c6eeb9a231e2859bc6af7b0a428fd975c5f6fc6
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
- CONF_DATA_TEST : key section to use from YML file for test data
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
- require 'auto_data'
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
- ###Switch global keys
41
+ ENV["AUTO_DATA_PATH"] = File.dirname(__FILE__)
53
42
 
54
- Switch global keys variable in runtime
43
+ #Create AutoData object
44
+ autodata = AutoData::Parse.new
55
45
 
56
- ```ruby
57
- login.change_scope('customer')
58
- env.change_scope('uat')
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
- #Use the information as you have defined in the yml conf file
61
- puts login.login #=> customer_id
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.
@@ -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
- result= begin @file["#{@data}"]["#{method}"].nil? ? 'No Value Found' : @file["#{@data}"]["#{method}"]
35
- rescue NoMethodError => e
36
- puts "valdio dick #{e.message}"
37
- end
6
+ class Parse
7
+ #TODO: Make all methods private
8
+ def initialize()
9
+ @gvar=ENV['AUTO_DATA_PATH'].to_s
38
10
 
39
- result
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
- #TODO: Validar si el cambio de data scope, es correcto (existe)
43
- def valid_data?
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
- end
26
+ end
48
27
 
49
- class Env
50
-
51
- def initialize()
52
- @env = ENV['CONF_ENV_TEST'].to_s.downcase
53
- end
28
+ def load(file)
54
29
 
55
- def load(file)
56
- #@file = YAML.load_file(file)
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
- #Change environment key path
66
- def change_scope(env)
67
- @env=env.to_s.downcase
68
- end
69
-
70
- def method_missing (method)
71
- result= begin @file["#{@env}"]["#{method}"].nil? ? 'No Value Found' : @file["#{@env}"]["#{method}"]
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
- result
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
- #TODO: Validar si el cambio de env, es correcto (existe)
79
- def valid_environment?
64
+ result
65
+ end
80
66
 
81
- end
82
67
  end
83
68
  end
@@ -1,3 +1,3 @@
1
1
  module AutoData
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Aguilar