Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pretty printing for value schemas

Change-Id: Ic7e3e388d9ac7a5cb22c83a6ae523201796d8ad7
  • Loading branch information...
commit 90b1fe73996d28efe31d5024a514c00d306a050e 1 parent 91d34d1
mpage authored
Showing with 26 additions and 3 deletions.
  1. +16 −3 lib/membrane/schema_parser.rb
  2. +10 −0 spec/schema_parser_spec.rb
View
19 lib/membrane/schema_parser.rb
@@ -6,9 +6,9 @@ module Membrane
class Membrane::SchemaParser
class Dsl
OptionalKeyMarker = Struct.new(:key)
- DictionaryMarker = Struct.new(:key_schema, :value_schema)
- EnumMarker = Struct.new(:elem_schemas)
- TupleMarker = Struct.new(:elem_schemas)
+ DictionaryMarker = Struct.new(:key_schema, :value_schema)
+ EnumMarker = Struct.new(:elem_schemas)
+ TupleMarker = Struct.new(:elem_schemas)
def any
Membrane::Schema::Any.new
@@ -39,12 +39,25 @@ def self.parse(&blk)
new.parse(&blk)
end
+ def self.deparse(schema)
+ new.deparse(schema)
+ end
+
def parse(&blk)
intermediate_schema = Dsl.new.instance_eval(&blk)
do_parse(intermediate_schema)
end
+ def deparse(schema)
+ case schema
+ when Membrane::Schema::Value
+ schema.value.inspect
+ else
+ schema.inspect
+ end
+ end
+
private
def do_parse(object)
View
10 spec/schema_parser_spec.rb
@@ -3,6 +3,16 @@
describe Membrane::SchemaParser do
let(:parser) { Membrane::SchemaParser.new }
+ describe "#deparse" do
+ it "should call inspect on the value of a Value schema" do
+ val = "test"
+ val.should_receive(:inspect).twice
+ schema = Membrane::Schema::Value.new(val)
+
+ Membrane::SchemaParser.deparse(schema).should == val.inspect
+ end
+ end
+
describe "#parse" do
it "should leave instances derived from Membrane::Schema::Base unchanged" do
old_schema = Membrane::Schema::ANY
Please sign in to comment.
Something went wrong with that request. Please try again.