data_builder 0.2.0 → 1.0.0

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: 24aa0d4e8e24c2d43cb2b24e4cf02cf87f5968bd
4
- data.tar.gz: 03a81f95a587216a1407342171b0721a4cb93191
3
+ metadata.gz: 5ffa6367098c65adf86a4c45a05c9a3cf68d9ea8
4
+ data.tar.gz: 6714fbdb50f5342f6706947b1d6e581507bbbb86
5
5
  SHA512:
6
- metadata.gz: a841011ab6f7c2fc74f1597845d3ecd60c7e4f909cd96eaa73ea025edb46d3fe8bf76d86eb289434aef72e16aaededaf59afe609f82b5d9d4635b745e0d099e3
7
- data.tar.gz: c8c972df9e1544f92b48539db7595223ce45e7ae76ee8b382d1841e4244a2e2daaecf983fa37b602026df7d61264810f3d90d19b8fb3ed5add2663b46f49080c
6
+ metadata.gz: dd34e50ba54ad2d37605e66b84529e5f99bdf95141bbdaec8036707c9c0927ec8d848db48311d8011d0fb7d48ec2bdf8802489039666e305c198442b00ad600c
7
+ data.tar.gz: 30fa6c54b64e20bfc29fa356e2af558efd812a1bda3564325c61d8218d91153159157367a28b2e5c72c26182f395a53ca66732f5fd9a6035371c17a5d83f7dc4
data/.hound.yml CHANGED
@@ -30,15 +30,15 @@ Style/SignalException:
30
30
  Enabled: false
31
31
 
32
32
  # This never works for validations.
33
- Style/AlignHash:
33
+ Layout/AlignHash:
34
34
  EnforcedLastArgumentHashStyle: ignore_implicit
35
35
 
36
36
  # Align multi-line params with previous line.
37
- Style/AlignParameters:
37
+ Layout/AlignParameters:
38
38
  EnforcedStyle: with_fixed_indentation
39
39
 
40
40
  # Indent `when` clause one step from `case`.
41
- Style/CaseIndentation:
41
+ Layout/CaseIndentation:
42
42
  IndentOneStep: true
43
43
 
44
44
  # Don't force bad var names for reduce/inject loops.
@@ -46,7 +46,7 @@ Style/SingleLineBlockParams:
46
46
  Enabled: false
47
47
 
48
48
  # For method chains, keep the dot with the method name.
49
- Style/DotPosition:
49
+ Layout/DotPosition:
50
50
  EnforcedStyle: leading
51
51
 
52
52
  # Stop nesting so hard.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/data_builder.svg)](http://badge.fury.io/rb/data_builder)
4
4
  [![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jeffnyman/data_builder/blob/master/LICENSE.txt)
5
5
 
6
- [![Dependency Status](https://gemnasium.com/jnyman/data_builder.png)](https://gemnasium.com/jnyman/data_builder)
6
+ [![Dependency Status](https://gemnasium.com/jeffnyman/data_builder.png)](https://gemnasium.com/jeffnyman/data_builder)
7
7
 
8
8
  The goal of DataBuilder is to apply an expressive means of constructing a data set based on information stored in YAML files.
9
9
 
@@ -25,25 +25,48 @@ You can also install DataBuilder just as you would any other gem:
25
25
 
26
26
  ## Usage
27
27
 
28
- DataBuilder is using my [DataReader gem](https://github.com/jeffnyman/data_reader) to provide base-level functionality. Unlike DataReader, DataBuilder will assume some defaults. For example, you could do something as simple as this:
28
+ DataBuilder is using my [DataReader gem](https://github.com/jeffnyman/data_reader) to provide base-level functionality. Unlike DataReader, DataBuilder will assume some defaults.
29
+
30
+ ### Loading with Default Path
31
+
32
+ Consider the following file and directory setup:
33
+
34
+ ```
35
+ project_dir\
36
+ config\
37
+ config.yml
38
+
39
+ data\
40
+ stars.yml
41
+
42
+ env\
43
+ environments.yml
44
+
45
+ example-data-builder.rb
46
+ ```
47
+
48
+ All the code shown below would go in the `example-data-builder` file.
49
+
50
+ With the above class in place and the above directory structure, you could do something as simple as this:
29
51
 
30
52
  ```ruby
31
53
  require "data_builder"
32
54
 
33
- data = DataBuilder.load 'default.yml'
55
+ data = DataBuilder.load 'stars.yml'
34
56
 
35
57
  puts data
36
58
  ```
37
59
 
38
- Here I'm relying on the fact that DataBuilder applies a default directory of `data`. I then use the `load` method of DataReader to call up a file in that directory. I could set my own data path with DataBuilder as such:
60
+ Here I'm relying on the fact that DataBuilder applies a default directory of `data`. I then use the `load` method of DataReader to call up a file in that directory.
61
+
62
+ ### Loading with Specified Path
63
+
64
+ You can set a specific data path with DataBuilder as such:
39
65
 
40
66
  ```ruby
41
67
  require "data_builder"
42
68
 
43
- DataBuilder.data_path = 'config/data'
44
- data = DataBuilder.load 'default.yml'
45
-
46
- puts data
69
+ DataBuilder.data_path = 'env'
47
70
  ```
48
71
 
49
72
  Here you can inform DataBuilder where it can find the data files using `data_path`. As you've seen, if you don't specify a directory then DataBuilder will default to using a directory named `data`.
@@ -51,10 +74,16 @@ Here you can inform DataBuilder where it can find the data files using `data_pat
51
74
  After setting the directory you must load a file. This can be accomplished by calling the `load` method.
52
75
 
53
76
  ```ruby
54
- DataBuilder.load 'default.yml'
77
+ data = DataBuilder.load 'environments.yml'
78
+
79
+ puts data
55
80
  ```
56
81
 
57
- However, these approaches are really just using DataBuilder as an overlay for DataReader.
82
+ Here the `data` variable would contain the contents of the `environments.yml` file.
83
+
84
+ However, everything said so far is really just using DataBuilder as an overlay for DataReader.
85
+
86
+ ### Data About
58
87
 
59
88
  Where DataBuilder steps in is when you want to use the data. DataBuilder provides a `data_about` method that will return the data for a specific key from any data files that have been loaded.
60
89
 
@@ -72,9 +101,9 @@ epsilon eridani:
72
101
  distance: 10.5
73
102
  ```
74
103
 
75
- Now let's use DataBuilder to get the information from it.
104
+ Now let's use DataBuilder to get the information from it. You can extend or include DataBuilder as part of another class.
76
105
 
77
- ### Extending DataBuilder
106
+ #### Extending DataBuilder
78
107
 
79
108
  ```ruby
80
109
  class Testing
@@ -84,7 +113,7 @@ end
84
113
  data = Testing.data_about('alpha centauri')
85
114
  ```
86
115
 
87
- ### Including DataBuilder
116
+ #### Including DataBuilder
88
117
 
89
118
  ```ruby
90
119
  class Testing
@@ -97,9 +126,9 @@ data = testing.data_about('alpha centauri')
97
126
 
98
127
  ### The Data Key
99
128
 
100
- In both cases of extending or including, I'm using a variable to store the results of the call. Those results will be the data pulled from the `default.yml` file. Of note, however, is that all that will be pulled is the data from the "alpha centauri" key because that is what you specified in the call to `data_about`.
129
+ In both cases of extending or including, I'm using a variable to store the results of the call. Those results will be the data pulled from the `default.yml` file. Of note, however, is all that will be pulled is the data from the "alpha centauri" key because that is what you specified in the call to `data_about`.
101
130
 
102
- In these examples, I'm using a string because the value "alpha centauri" has a space in it. However, if that was not the case -- if the key were, say, alpha_centauri -- then you could use a symbol instead, like this:
131
+ Those examples show `data_about` being passed a string and the reason for that is because the value "alpha centauri" has a space in it. However, if that was not the case -- if the key were, say, "alpha_centauri" -- then you could use a symbol instead, like this:
103
132
 
104
133
  ```ruby
105
134
  data = testing.data_about(:alpha_centauri)
@@ -107,15 +136,15 @@ data = testing.data_about(:alpha_centauri)
107
136
 
108
137
  ### Default Files
109
138
 
110
- You might wonder how DataBuilder knew to look for `default.yml` since I didn't use a `load` method in these examples. If you do not specify a filename the logic will attempt to use a file named `default.yml` in the data path you have specified or in the default path of `data`.
139
+ You might wonder how DataBuilder knew to look for `default.yml` since I didn't use a `load` method in these examples. If you do not specify a filename the logic will attempt to use a file named `default.yml` in the specific data path you have specified or in the default path of `data`.
111
140
 
112
- Another option is that you can set an environment variable called DATA_BUILDER_SOURCE. When this variable exists and is set, the value it is set to will be used instead of the `default.yml` file. Keep in mind that the "data source" here refers to the file, not the keys within a file.
141
+ Another option is that you can set an environment variable called `DATA_BUILDER_SOURCE`. When this variable exists and is set, the value it is set to will be used instead of the `default.yml` file. Keep in mind that the "data source" here refers to the file, not the keys within a file.
113
142
 
114
143
  ### Namespaced Data
115
144
 
116
145
  To organize your data into a rough equivalent of namespaces, and to load that data accordingly, you can do something like this:
117
146
 
118
- ```
147
+ ```ruby
119
148
  class Testing
120
149
  include DataBuilder
121
150
  end
@@ -125,7 +154,7 @@ testing = Testing.new
125
154
  data = testing.data_about('stars/epsilon eridani')
126
155
  ```
127
156
 
128
- When DataBuilder sees this kind of construct, it will take the first part (before the /) as a filename and the second part as the key to look up in that file. So the above command would look for a file called `stars.yml` in the data path provided and then grab the data from the key entry labeled "epislon eridani".
157
+ When DataBuilder sees this kind of construct, it will take the first part (before the /) as a filename and the second part as the key to look up in that file. So the above command would look for a file called `stars.yml` in the data path provided (in this case, the default of `data`) and then grab the data from the key entry labeled "epislon eridani".
129
158
 
130
159
  ### Aliases
131
160
 
@@ -136,6 +165,8 @@ Given the examples, you can see that `data_about` was chosen as the method name
136
165
  * `using_data_for`
137
166
  * `using_data_from`
138
167
 
168
+ The reason for these aliases is, again, to make the logic expressive about its intent. This is particularly nice if you fit DataBuilder in with the context of a fluent API.
169
+
139
170
  ## Development
140
171
 
141
172
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec:all` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.
data/Rakefile CHANGED
@@ -13,9 +13,9 @@ namespace :spec do
13
13
  end
14
14
 
15
15
  RSpec::Core::RakeTask.new(all: :clean) do |config|
16
- options = %w(--color)
17
- options += %w(--format documentation)
18
- options += %w(--format html --out spec/reports/unit-test-report.html)
16
+ options = %w[--color]
17
+ options += %w[--format documentation]
18
+ options += %w[--format html --out spec/reports/unit-test-report.html]
19
19
 
20
20
  config.rspec_opts = options
21
21
  end
data/data/account.yml ADDED
@@ -0,0 +1,3 @@
1
+ test:
2
+ name: TesterStories
3
+ owner: Jeff Nyman
data/data/default.yml ADDED
@@ -0,0 +1,3 @@
1
+ test:
2
+ data_01: xyzzy
3
+ data_02: zzyzx
data/lib/data_builder.rb CHANGED
@@ -11,6 +11,13 @@ module DataBuilder
11
11
  def default_data_path
12
12
  'data'
13
13
  end
14
+
15
+ def data_files_for(scenario)
16
+ tags = scenario.send(scenario.respond_to?(:tags) ? :tags : :source_tags)
17
+ tags.map(&:name).select { |t| t =~ /@databuilder_/ }.map do |t|
18
+ t.gsub('@databuilder_', '').to_sym
19
+ end
20
+ end
14
21
  end
15
22
 
16
23
  def data_about(key, specified = {})
@@ -33,6 +40,14 @@ module DataBuilder
33
40
  alias using_data_for data_about
34
41
  alias using_data_from data_about
35
42
 
43
+ def self.use_in_scenario(scenario, data_location = DataBuilder.data_path)
44
+ original_data_path = DataBuilder.data_path
45
+ DataBuilder.data_path = data_location
46
+ data_files = data_files_for(scenario)
47
+ DataBuilder.load("#{data_files.last}.yml") if data_files.count > 0
48
+ DataBuilder.data_path = original_data_path
49
+ end
50
+
36
51
  private
37
52
 
38
53
  def builder_source
@@ -1,3 +1,3 @@
1
1
  module DataBuilder
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Nyman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,6 +113,8 @@ files:
113
113
  - Rakefile
114
114
  - bin/console
115
115
  - bin/setup
116
+ - data/account.yml
117
+ - data/default.yml
116
118
  - data_builder.gemspec
117
119
  - lib/data_builder.rb
118
120
  - lib/data_builder/version.rb
@@ -121,7 +123,7 @@ licenses:
121
123
  - MIT
122
124
  metadata: {}
123
125
  post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
124
- \ DataBuilder 0.2.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::)
126
+ \ DataBuilder 1.0.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::)
125
127
  (::) (::) (::) (::)\n "
126
128
  rdoc_options: []
127
129
  require_paths:
@@ -138,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  version: '0'
139
141
  requirements: []
140
142
  rubyforge_project:
141
- rubygems_version: 2.5.1
143
+ rubygems_version: 2.6.13
142
144
  signing_key:
143
145
  specification_version: 4
144
146
  summary: Provides expressive data set handling from YAML files.