membrane 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -2
- data/lib/membrane/schema/base.rb +4 -0
- data/lib/membrane/schema/dictionary.rb +1 -1
- data/lib/membrane/schema_parser.rb +2 -6
- data/lib/membrane/version.rb +1 -1
- data/spec/base_schema_spec.rb +16 -0
- data/spec/schema_parser_spec.rb +8 -3
- metadata +3 -1
data/README.md
CHANGED
@@ -17,7 +17,8 @@ Membrane provides a handful of useful schemas out of the box. You should be
|
|
17
17
|
able to construct the majority of your schemas using only what is provided
|
18
18
|
by default. The provided schemas are:
|
19
19
|
|
20
|
-
* _Any_ - Accepts all values. Use it sparingly.
|
20
|
+
* _Any_ - Accepts all values. Use it sparingly. It is synonymous to
|
21
|
+
class Object in Ruby.
|
21
22
|
* _Bool_ - Accepts ```true``` and ```false```.
|
22
23
|
* _Class_ - Accepts instances of a supplied class.
|
23
24
|
* _Dictionary_ - Accepts hashes whose keys and values validate against their
|
@@ -63,7 +64,7 @@ be self-explanatory.
|
|
63
64
|
Membrane::SchemaParser.parse do
|
64
65
|
{ "ints" => [Integer]
|
65
66
|
"true_or_false" => bool,
|
66
|
-
"anything" => any,
|
67
|
+
"anything" => any, # You can also use Object instead.
|
67
68
|
optional("_") => any,
|
68
69
|
"one_or_two" => enum(1, 2),
|
69
70
|
"strs_to_ints" => dict(String, Integer),
|
data/lib/membrane/schema/base.rb
CHANGED
@@ -58,7 +58,7 @@ class Membrane::SchemaParser
|
|
58
58
|
when Membrane::Schema::Bool
|
59
59
|
"bool"
|
60
60
|
when Membrane::Schema::Class
|
61
|
-
schema.klass.
|
61
|
+
schema.klass.name
|
62
62
|
when Membrane::Schema::Dictionary
|
63
63
|
"dict(%s, %s)" % [deparse(schema.key_schema),
|
64
64
|
deparse(schema.value_schema)]
|
@@ -75,11 +75,7 @@ class Membrane::SchemaParser
|
|
75
75
|
when Membrane::Schema::Value
|
76
76
|
schema.value.inspect
|
77
77
|
when Membrane::Schema::Base
|
78
|
-
|
79
|
-
schema.deparse
|
80
|
-
else
|
81
|
-
schema.inspect
|
82
|
-
end
|
78
|
+
schema.inspect
|
83
79
|
else
|
84
80
|
emsg = "Expected instance of Membrane::Schema::Base, given instance of" \
|
85
81
|
+ " #{schema.class}"
|
data/lib/membrane/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe Membrane::Schema::Base do
|
5
|
+
describe "#validate" do
|
6
|
+
let(:schema) { Membrane::Schema::Base.new }
|
7
|
+
|
8
|
+
it "should raise error" do
|
9
|
+
expect { schema.validate }.to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should deparse" do
|
13
|
+
schema.deparse.should == schema.inspect
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/schema_parser_spec.rb
CHANGED
@@ -24,12 +24,12 @@ describe Membrane::SchemaParser do
|
|
24
24
|
parser.deparse(schema).should == "bool"
|
25
25
|
end
|
26
26
|
|
27
|
-
it "should call
|
27
|
+
it "should call name on the class of a Membrane::Schema::Class schema" do
|
28
28
|
klass = String
|
29
|
-
klass.should_receive(:
|
29
|
+
klass.should_receive(:name).twice
|
30
30
|
schema = Membrane::Schema::Class.new(klass)
|
31
31
|
|
32
|
-
parser.deparse(schema).should == klass.
|
32
|
+
parser.deparse(schema).should == klass.name
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should deparse the k/v schemas of a Membrane::Schema::Dictionary schema" do
|
@@ -99,6 +99,11 @@ EOT
|
|
99
99
|
parser.deparse(enum_schema).should == 'tuple(String, Integer, "test")'
|
100
100
|
end
|
101
101
|
|
102
|
+
it "should call inspect on a Membrane::Schema::Base schema" do
|
103
|
+
schema = Membrane::Schema::Base.new
|
104
|
+
parser.deparse(schema).should == schema.inspect
|
105
|
+
end
|
106
|
+
|
102
107
|
it "should raise an error if given a non-schema" do
|
103
108
|
expect do
|
104
109
|
parser.deparse({})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: membrane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/membrane/version.rb
|
91
91
|
- membrane.gemspec
|
92
92
|
- spec/any_schema_spec.rb
|
93
|
+
- spec/base_schema_spec.rb
|
93
94
|
- spec/bool_schema_spec.rb
|
94
95
|
- spec/class_schema_spec.rb
|
95
96
|
- spec/complex_schema_spec.rb
|
@@ -128,6 +129,7 @@ specification_version: 3
|
|
128
129
|
summary: A DSL for validating data.
|
129
130
|
test_files:
|
130
131
|
- spec/any_schema_spec.rb
|
132
|
+
- spec/base_schema_spec.rb
|
131
133
|
- spec/bool_schema_spec.rb
|
132
134
|
- spec/class_schema_spec.rb
|
133
135
|
- spec/complex_schema_spec.rb
|