data_reader 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -20
- data/lib/data_reader.rb +6 -0
- data/lib/data_reader/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8152cfa583503a6a29c82d1827b34f49010befe3
|
4
|
+
data.tar.gz: 4efc7ea01d4a6d1c6ab26d040da8b9674a6b6062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 109adba9cd271069b31dc14dfa9cad47542c052ac69e4b1f1acdb993686400e8677a7efc51bf7fadc218687d1e886fb7c28d446c758cc6bc1c0acc43903ad622
|
7
|
+
data.tar.gz: d4eedbbd0d127e8db4e389fe73522d991d9645c85359add46a5f58d28338ffb5ef8d4c1228c3cf0a2e2fe1b8f2a9dc8b74700a5b9598cb221dcdae75e76bed8c
|
data/README.md
CHANGED
@@ -20,44 +20,107 @@ You can also install DataReader just as you would any other gem:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
### Including DataReader
|
24
|
+
|
25
|
+
You can include the DataReader in a class or module.
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
|
27
|
-
|
28
|
+
require "data_reader"
|
29
|
+
|
30
|
+
class Testing
|
31
|
+
include DataReader
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
DataReader does not set defaults for anything. It does hold a `data_path` that you set. It holds a `data_source` that is populated with the result of a file load.
|
36
|
+
|
37
|
+
With the above class in place, you could do this:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
test = Testing.new
|
41
|
+
|
42
|
+
test.data_path = 'data'
|
43
|
+
|
44
|
+
puts test.data_path
|
45
|
+
|
46
|
+
test.load 'default.yml'
|
47
|
+
|
48
|
+
puts test.data_source
|
49
|
+
```
|
50
|
+
|
51
|
+
Here you are setting the `data_path` to a directory called `data`. The `puts` statement after that simply confirms that this was set. You then call the `load` method for a YAML file that is in that directory. The `puts` call for the `data_source` will show you the contents of the YAML.
|
52
|
+
|
53
|
+
You could have specified the `data_path` as part of the class instead, like this:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class Testing
|
57
|
+
include DataReader
|
58
|
+
|
59
|
+
def data_path
|
60
|
+
'data'
|
61
|
+
end
|
28
62
|
end
|
29
63
|
```
|
30
64
|
|
31
|
-
|
65
|
+
Then you don't have to set the path specifically.
|
32
66
|
|
33
|
-
|
34
|
-
* `data_path`
|
35
|
-
* `load`
|
67
|
+
You can load multiple YAML files. The `load` method takes a list of comma separated names of files that are in that same directory.
|
36
68
|
|
37
|
-
|
69
|
+
```ruby
|
70
|
+
load 'users.yml, accounts.yml, billing.yml'
|
71
|
+
```
|
72
|
+
|
73
|
+
When loading in multiple files, the `data_source` will hold the contents of all the files in the list.
|
74
|
+
|
75
|
+
### Extending DataReader
|
76
|
+
|
77
|
+
You can also extend, rather than include, DataReader. This means you deal with the class rather than an instance of it. For example:
|
38
78
|
|
39
|
-
|
40
|
-
|
79
|
+
```ruby
|
80
|
+
require "data_reader"
|
41
81
|
|
42
|
-
|
82
|
+
class Testing
|
83
|
+
extend DataReader
|
84
|
+
end
|
43
85
|
|
44
|
-
|
86
|
+
Testing.data_path = 'data'
|
45
87
|
|
46
|
-
|
88
|
+
puts Testing.data_path
|
47
89
|
|
48
|
-
|
90
|
+
Testing.load 'default.yml'
|
91
|
+
|
92
|
+
puts Testing.data_source
|
93
|
+
```
|
94
|
+
|
95
|
+
Note that you can provide methods as you did in the include class, but make sure they are defined on `self`. For example:
|
49
96
|
|
50
97
|
```ruby
|
51
|
-
|
98
|
+
class Testing
|
99
|
+
extend DataReader
|
100
|
+
|
101
|
+
def self.data_path
|
102
|
+
'data'
|
103
|
+
end
|
104
|
+
end
|
52
105
|
```
|
53
106
|
|
54
|
-
|
107
|
+
### Default Path
|
108
|
+
|
109
|
+
You can, at any time, set a data path. When you do, any calls to `load` will use that data path. However, you may want to make sure that a default data path is always available should a data path not have been specifically set. You can do that as follows:
|
55
110
|
|
56
111
|
```ruby
|
57
|
-
|
112
|
+
class Testing
|
113
|
+
include DataReader
|
114
|
+
|
115
|
+
def default_data_path
|
116
|
+
'data'
|
117
|
+
end
|
118
|
+
end
|
58
119
|
```
|
59
120
|
|
60
|
-
|
121
|
+
Remember to add a `self` to the method call if you are extending DataReader.
|
122
|
+
|
123
|
+
Keep in mind that DataReader will always favor whatever it has stored in `data_path`. The `default_data_path` can be used for a fallback.
|
61
124
|
|
62
125
|
### Parameterizing Files
|
63
126
|
|
@@ -75,6 +138,8 @@ The support for ERB allows for custom calls. One that is included with DataReade
|
|
75
138
|
<%= include_data("my_data.yml") %>
|
76
139
|
```
|
77
140
|
|
141
|
+
If the above line was in a file called `default.yml` and you used the `load 'default.yml'` command, then, because of the call to `include_data` you would end up with the data from both files.
|
142
|
+
|
78
143
|
## Development
|
79
144
|
|
80
145
|
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`.
|
@@ -83,7 +148,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
83
148
|
|
84
149
|
Bug reports and pull requests are welcome on GitHub at [https://github.com/jnyman/data_reader](https://github.com/jnyman/data_reader). The testing ecosystem of Ruby is very large and this project is intended to be a welcoming arena for collaboration on yet another testing tool. As such, contributors are very much welcome but are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
85
150
|
|
86
|
-
To contribute to
|
151
|
+
To contribute to DataReader:
|
87
152
|
|
88
153
|
1. [Fork the project](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/).
|
89
154
|
2. Create your feature branch. (`git checkout -b my-new-feature`)
|
@@ -97,7 +162,7 @@ To contribute to Decohere:
|
|
97
162
|
|
98
163
|
## Credits
|
99
164
|
|
100
|
-
This code is based upon the [YmlReader](https://github.com/cheezy/yml_reader) gem. I wanted to make a more generic version that may not be focused only on YAML files.
|
165
|
+
This code is based upon the [YmlReader](https://github.com/cheezy/yml_reader) gem. I wanted to give myself room to make a more generic version that may not be focused only on YAML files. More importantly, I wanted to clean up the implementation and documentation a bit.
|
101
166
|
|
102
167
|
## License
|
103
168
|
|
data/lib/data_reader.rb
CHANGED
@@ -13,8 +13,14 @@ module DataReader
|
|
13
13
|
nil
|
14
14
|
end
|
15
15
|
|
16
|
+
def data_source
|
17
|
+
return @data_source if @data_source
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
16
21
|
def load(file_list)
|
17
22
|
files = file_list.include?(',') ? file_list.split(',') : [file_list]
|
23
|
+
files = files.collect(&:strip)
|
18
24
|
@data_source = files.inject({}) do |data, file|
|
19
25
|
data.merge!(YAML.load(
|
20
26
|
ERB.new(File.read("#{data_path}/#{file}")).result(binding)
|
data/lib/data_reader/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
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-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,7 +107,7 @@ licenses:
|
|
107
107
|
- MIT
|
108
108
|
metadata: {}
|
109
109
|
post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
|
110
|
-
\ DataReader
|
110
|
+
\ DataReader 1.0.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::)
|
111
111
|
(::) (::) (::) (::)\n "
|
112
112
|
rdoc_options: []
|
113
113
|
require_paths:
|