sexy_json_schemas 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sexy_json_schemas/dsl.rb +6 -4
- data/sexy_json_schemas.gemspec +1 -1
- data/spec/sexy_json_schemas_spec.rb +23 -0
- metadata +2 -2
@@ -2,9 +2,9 @@ module SexyJSONSchemas
|
|
2
2
|
module DSL
|
3
3
|
def schema(name, options = {}, &block)
|
4
4
|
options[:root_element] ||= name unless options[:root_element] == false
|
5
|
-
@schema_name
|
6
|
-
@
|
7
|
-
@
|
5
|
+
@schema_name = name
|
6
|
+
@schema_options = options
|
7
|
+
@definition_block = block
|
8
8
|
end
|
9
9
|
|
10
10
|
def schema_name
|
@@ -12,7 +12,9 @@ module SexyJSONSchemas
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def as_json
|
15
|
-
|
15
|
+
definition = SchemaDefinition.new(@schema_name, @schema_options)
|
16
|
+
definition.instance_eval(&@definition_block)
|
17
|
+
definition.as_json
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/sexy_json_schemas.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "sexy_json_schemas"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.6"
|
8
8
|
gem.authors = ["Donald Plummer", "Michael Xavier"]
|
9
9
|
gem.email = ["donald@crystalcommerce.com", "xavier@crystalcommerce.com"]
|
10
10
|
gem.description = %q{A DSL for generating JSON Schemas}
|
@@ -322,4 +322,27 @@ describe SexyJSONSchemas do
|
|
322
322
|
|
323
323
|
it_should_behave_like "valid schema generator"
|
324
324
|
end
|
325
|
+
|
326
|
+
describe "dynamic calls in schema definition" do
|
327
|
+
before(:each) do
|
328
|
+
|
329
|
+
end
|
330
|
+
subject { }
|
331
|
+
|
332
|
+
it "dynamically calls the schema" do
|
333
|
+
global_var = "bob"
|
334
|
+
subject = Class.new(JSONTestClass) {
|
335
|
+
schema "void", :root_element => "wat" do
|
336
|
+
ref_property "name", global_var
|
337
|
+
end
|
338
|
+
}
|
339
|
+
subject.as_json['properties']['wat']['properties']['name'].
|
340
|
+
should == {"$ref" => "bob"}
|
341
|
+
|
342
|
+
global_var = "fred"
|
343
|
+
|
344
|
+
subject.as_json['properties']['wat']['properties']['name'].
|
345
|
+
should == {"$ref" => "fred"}
|
346
|
+
end
|
347
|
+
end
|
325
348
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sexy_json_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|