schemad 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/README.md +10 -5
- data/lib/schemad/default_types.rb +5 -0
- data/lib/schemad/version.rb +1 -1
- data/lib/schemad.rb +1 -0
- data/spec/entity_spec.rb +1 -1
- data/spec/type_handler_spec.rb +3 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d65d60e8c0d2976ed42bd8ab10ebaed58f4e1010
|
4
|
+
data.tar.gz: 74d74e0511eb3accaaebd48c240d05b4e0f33f89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b085350cfd29b11fd7e9e535256b67c774afc0b90ccfc44999a024a1d84ea85b191d56b1896d751e20f1a4e80a68c0654c180d9fad2035badceadd1511ab5450
|
7
|
+
data.tar.gz: 969ceaef8a69f3e951d2da2583138551d72e5d9c948e41a32704785b21c1ebeb77eba05cb36feae7ccda61aa67c8f15695ec2b3711353c3fed64308746509254
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
# Schemad
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/schemad.svg)](http://badge.fury.io/rb/schemad)
|
4
|
+
[![Build Status](https://travis-ci.org/plukevdh/schemad.svg?branch=master)](https://travis-ci.org/plukevdh/schemad)
|
5
|
+
|
3
6
|
Schemad is a simple metagem to aid integrating legacy or third-party datasets into other projects. It's especially geared towards unifying multiple datasets into consistent data structures for ease of and consistency in use.
|
4
7
|
|
5
8
|
This gem has two main parts: Normalizers and Entities.
|
6
9
|
|
7
10
|
## Normalizers
|
8
11
|
|
9
|
-
Normalizers are the translators between different datasets. They take misshaped data and help mold it into a consistent form before turning them into objects for general use.
|
12
|
+
Normalizers are the translators between different datasets. They take misshaped data and help mold it into a consistent form before turning them into objects for general use.
|
10
13
|
|
11
14
|
For example, let's say I want to pull commit data from [GitHub](https://github.com) and [BitBucket](https://bitbucket.org) and do something with the two datasets. Let's look at the API for both and the kind of data they return for a commit object.
|
12
15
|
|
@@ -167,7 +170,7 @@ github_data = JSON.parse(raw_json)
|
|
167
170
|
parsed = GitHubNormalizer.new.normalize(github_data)
|
168
171
|
```
|
169
172
|
|
170
|
-
And we should then have a plain hash much like the following:
|
173
|
+
And we should then have a plain hash much like the following:
|
171
174
|
|
172
175
|
```ruby
|
173
176
|
{
|
@@ -205,7 +208,7 @@ Now the normalizer will use the raw field and pick out the email using a regex m
|
|
205
208
|
|
206
209
|
## Entities
|
207
210
|
|
208
|
-
Entities provide consistent [value objects](http://martinfowler.com/bliki/ValueObject.html) that allow for easily transporting the data to functionality that uses the data. Entities are very limited in functionality and are mainly meant to provide a more ruby-ish means of accessing the data. We _could_ pass around the normalized hashes, but typically, we rubyists like having method access to our data:
|
211
|
+
Entities provide consistent [value objects](http://martinfowler.com/bliki/ValueObject.html) that allow for easily transporting the data to functionality that uses the data. Entities are very limited in functionality and are mainly meant to provide a more ruby-ish means of accessing the data. We _could_ pass around the normalized hashes, but typically, we rubyists like having method access to our data:
|
209
212
|
|
210
213
|
```ruby
|
211
214
|
commit.comment # "added readme, because im a good github citizen\n"
|
@@ -213,7 +216,7 @@ commit.id # "7638417db6d59f3c431d3e1f261cc637155684cd"
|
|
213
216
|
comment.created_date # A time object!
|
214
217
|
```
|
215
218
|
|
216
|
-
So this is what Entities provide.
|
219
|
+
So this is what Entities provide.
|
217
220
|
|
218
221
|
```ruby
|
219
222
|
class Commit < Schemad::Entity
|
@@ -233,6 +236,8 @@ Note that the default attribute type (if not provided) is a string (`:string`).
|
|
233
236
|
- :integer
|
234
237
|
- :boolean
|
235
238
|
|
239
|
+
To get these types, simply `require 'schemad/default_types'`. They are not required by default to ensure that my Schemad's type handling is what you want explicity.
|
240
|
+
|
236
241
|
New types are easy to create, more on this in a moment.
|
237
242
|
|
238
243
|
To instantiate these new class, we use the `from_data` method to ensure parsing with the output from the normalizer step above:
|
@@ -252,7 +257,7 @@ comment.created_date # A time object!
|
|
252
257
|
|
253
258
|
You don't have to use the normalizers to use the `from_data` method. It can be any consistently formatted hash. The keys **must** be accessible by symbol however (use a hash with all symbols as keys or an ActiveSupport/Hashie/other [HashWithIndifferentAccess](http://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html) implementation).
|
254
259
|
|
255
|
-
In fact, both normalizer and entity can be used independent of one another if one or the other isn't required for your use. Just include the library you want:
|
260
|
+
In fact, both normalizer and entity can be used independent of one another if one or the other isn't required for your use. Just include the library you want:
|
256
261
|
|
257
262
|
```ruby
|
258
263
|
require 'schemad/type_handler'
|
data/lib/schemad/version.rb
CHANGED
data/lib/schemad.rb
CHANGED
data/spec/entity_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Schemad::Entity do
|
|
23
23
|
context "defaults or nil get used when no data" do
|
24
24
|
|
25
25
|
Then { ent.forest.should == "Green" }
|
26
|
-
And { ent.cool.should
|
26
|
+
And { ent.cool.should eq true }
|
27
27
|
And { ent.created.should eq(Time.now) }
|
28
28
|
And { ent.roads.should == 5 }
|
29
29
|
And { ent.world.should == "coordinates" }
|
data/spec/type_handler_spec.rb
CHANGED
@@ -41,14 +41,14 @@ describe Schemad::TypeHandler do
|
|
41
41
|
context "knows trues" do
|
42
42
|
Schemad::BooleanHandler::VALID_TRUTHS.each do |val|
|
43
43
|
When(:parsed) { bool_handler.parse(val) }
|
44
|
-
Then { parsed.should
|
44
|
+
Then { parsed.should eq true }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
context "rejects falses" do
|
49
49
|
[42, "Hello World", nil, String].each do |val|
|
50
50
|
When(:parsed) { bool_handler.parse(val) }
|
51
|
-
Then { parsed.should
|
51
|
+
Then { parsed.should eq false }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -122,4 +122,4 @@ describe Schemad::TypeHandler do
|
|
122
122
|
Then { result.to_i.should == date_time.to_time.to_i }
|
123
123
|
end
|
124
124
|
end
|
125
|
-
end
|
125
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke van der Hoeven
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -62,12 +62,14 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
68
69
|
- Rakefile
|
69
70
|
- lib/schemad.rb
|
70
71
|
- lib/schemad/abstract_handler.rb
|
72
|
+
- lib/schemad/default_types.rb
|
71
73
|
- lib/schemad/entity.rb
|
72
74
|
- lib/schemad/extensions.rb
|
73
75
|
- lib/schemad/normalizer.rb
|
@@ -104,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
106
|
version: '0'
|
105
107
|
requirements: []
|
106
108
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.5
|
108
110
|
signing_key:
|
109
111
|
specification_version: 4
|
110
112
|
summary: Simple schema DSL for services
|