data_package 0.0.9 → 0.0.10
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/lib/data_package/schema.rb +10 -1
- data/lib/data_package/version.rb +1 -1
- data/spec/data_package/schema_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82a81fd9c748fb4d2a4d138aa4a10303356762bf
|
4
|
+
data.tar.gz: e0748ef555fad62c84b42396d04a69c2bd4ecb85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82c9b285089afd248a35d4367111a237db709036f3e32fa1a91553a0db5e62fb48a75a935c33e0cdd695056dcc229e57a658becb3feec72602b8a01be974197f
|
7
|
+
data.tar.gz: 98bd24c91b056ec3cf7ca3de2ce7f6f81326bddb3975a2fb1db7ca6db22388277730dce07e0ed24b1084a5cc17e9b16edfa82a8a251599df1884ad96ef2d3931
|
data/lib/data_package/schema.rb
CHANGED
@@ -5,7 +5,8 @@ module DataPackage
|
|
5
5
|
}
|
6
6
|
|
7
7
|
attr_optional :primary_key, :key => 'primaryKey',
|
8
|
-
:
|
8
|
+
:if => Proc.new{|pkey| pkey && pkey.length > 0},
|
9
|
+
:serialize => Proc.new{|pkey| pkey && pkey.length == 1 ? pkey.first : pkey }
|
9
10
|
|
10
11
|
def initialize(attrs = {})
|
11
12
|
@fields ||= []
|
@@ -24,5 +25,13 @@ module DataPackage
|
|
24
25
|
@primary_key = [json]
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
def primary_key
|
30
|
+
@primary_key || []
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_primary_key?
|
34
|
+
primary_key.length > 0
|
35
|
+
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/data_package/version.rb
CHANGED
@@ -20,6 +20,7 @@ describe DataPackage::Schema do
|
|
20
20
|
schema.fields.length.should == 1
|
21
21
|
schema.fields.first.name.should == 'income'
|
22
22
|
schema.primary_key.should == ['income']
|
23
|
+
schema.has_primary_key?.should == true
|
23
24
|
|
24
25
|
modified_json = json.merge('primaryKey' => 'income')
|
25
26
|
schema.to_json.should == Yajl::Encoder.encode(modified_json, :pretty => true)
|
@@ -33,6 +34,19 @@ describe DataPackage::Schema do
|
|
33
34
|
schema.fields.length.should == 1
|
34
35
|
schema.fields.first.name.should == 'income'
|
35
36
|
schema.primary_key.should == ['income']
|
37
|
+
schema.has_primary_key?.should == true
|
38
|
+
schema.to_json.should == Yajl::Encoder.encode(modified_json, :pretty => true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have primary key accessor" do
|
42
|
+
modified_json = json.delete_if{|key, v| key == 'primaryKey'}
|
43
|
+
|
44
|
+
schema = DataPackage::Schema.new(modified_json)
|
45
|
+
|
46
|
+
schema.fields.length.should == 1
|
47
|
+
schema.fields.first.name.should == 'income'
|
48
|
+
schema.primary_key.should == []
|
49
|
+
schema.has_primary_key?.should == false
|
36
50
|
schema.to_json.should == Yajl::Encoder.encode(modified_json, :pretty => true)
|
37
51
|
end
|
38
52
|
end
|