json-schematized 0.2.2 → 0.2.3

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.
data/Gemfile CHANGED
@@ -1,9 +1,12 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
5
  gem 'virtus', :git => 'https://github.com/solnic/virtus'
6
6
 
7
+ # Gem activesupport ~> 4.0.0 requires Ruby ~> 1.9.3
8
+ gem 'activesupport', '~> 3.2.0'
9
+
7
10
  # RUBY_VERSION ~> "1.9.0"
8
11
  # gem "debugger"
9
12
 
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'virtus', '~> 0.5.0'
6
+
7
+ # Gem activesupport ~> 4.0.0 requires Ruby ~> 1.9.3
8
+ gem 'activesupport', '~> 3.2.0'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'virtus', :git => 'https://github.com/solnic/virtus'
6
+
7
+ # Gem activesupport ~> 4.0.0 requires Ruby ~> 1.9.3
8
+ gem 'activesupport', '~> 3.2.0'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '../'
4
+
5
+ # Gem activesupport ~> 4.0.0 requires Ruby ~> 1.9.3
6
+ gem 'activesupport', '~> 3.2.0'
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "json-schematized"
3
- s.version = "0.2.2"
3
+ s.version = "0.2.3"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "Object builder based on JSON-Schema"
6
6
  s.require_paths = ["lib"]
7
7
  s.files = `git ls-files -- Gemfile README.md lib/ script/ *.gemspec`.split("\n")
8
- s.test_files = `git ls-files -- .rspec Gemfile spec/`.split("\n")
8
+ s.test_files = `git ls-files -- .rspec Gemfile gemfiles/ spec/`.split("\n")
9
9
 
10
10
  s.description = ""
11
11
  s.authors = ["Marcelo Manzan"]
12
12
  s.email = "manzan@gmail.com"
13
- s.homepage = "http://github.com/abril"
13
+ s.homepage = "http://github.com/kawamanza"
14
14
 
15
15
  s.add_runtime_dependency "multi_json", "~> 1.0"
16
16
  s.add_runtime_dependency "activesupport"
@@ -36,8 +36,15 @@ module JSON
36
36
  def self.attribute_set
37
37
  unless defined?(@attribute_set)
38
38
  set = []
39
+ v1x = ::Virtus.respond_to?(:module)
39
40
  json_schema[:properties].each_pair do |field_name, meta|
40
- set << Virtus::Attribute.build(field_name, BasicWrapper.meta_type(self, field_name, meta))
41
+ args = [field_name, BasicWrapper.meta_type(self, field_name, meta), {:name => field_name}]
42
+ if v1x
43
+ args.shift
44
+ else
45
+ args.pop
46
+ end
47
+ set << Virtus::Attribute.build(*args)
41
48
  end
42
49
  @attribute_set = Virtus::AttributeSet.new(nil, set)
43
50
  end
@@ -0,0 +1,88 @@
1
+ # encoding: UTF-8
2
+
3
+ module JSON
4
+ module Schematized
5
+ module DSL
6
+ def virtus_module
7
+ VirtusWrapper.modularize(json_schema)
8
+ end
9
+ end
10
+
11
+ module VirtusWrapper
12
+ extend Wrapper
13
+
14
+ def self.included(base)
15
+ base.send(:include, modularize(base.json_schema))
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+ def json_schema_module
21
+ VirtusWrapper.modularize(json_schema)
22
+ end
23
+ end
24
+
25
+ def self.modularize(json_schema)
26
+ super(json_schema) do
27
+ include ::Virtus
28
+
29
+ VirtusWrapper.prepare_schema!(self, self.json_schema, :simple_types)
30
+ def self.included(base)
31
+ super
32
+ VirtusWrapper.prepare_schema!(base, json_schema, :complex_types)
33
+ end
34
+
35
+ def self.extend_object(base)
36
+ class_name = :ComplexTypes
37
+ (const_defined?(class_name) ?
38
+ const_get(class_name) :
39
+ const_set(class_name, Module.new)
40
+ ).tap do |klass|
41
+ klass.send(:include, self) unless klass.include?(self)
42
+ base.extend klass
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def self.prepare_model(ref, field_name, model_class, json_schema)
49
+ model_class.send(:include, modularize(json_schema))
50
+ end
51
+
52
+ def self.add_attribute!(ref, field_name, meta, kind)
53
+ opts = {}
54
+ klass = (kind.is_a?(Class) ? kind : kind.class)
55
+ if kind.is_a?(Class)
56
+ opts[:default] = klass.new if meta[:required] && kind.include?(::Virtus)
57
+ else
58
+ opts[:default] = kind.class.new
59
+ end
60
+ ref.attribute field_name, kind, opts
61
+ end
62
+
63
+ def self.collection_superclass
64
+ Array
65
+ end
66
+
67
+ class Array < ::Array
68
+ end
69
+
70
+ module Attribute
71
+ class Array < ::Virtus::Attribute::Array
72
+ primitive VirtusWrapper::Array
73
+ default primitive.new
74
+
75
+ def new_collection
76
+ (@primitive || self.class.primitive).new
77
+ end
78
+
79
+ def self.merge_options(type, options)
80
+ merged_options = super
81
+ klass = type.is_a?(Class) ? type : type.class
82
+ merged_options.merge(:primitive => klass)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: UTF-8
2
+
3
+ module JSON
4
+ module Schematized
5
+ module DSL
6
+ def virtus_module
7
+ VirtusWrapper.modularize(json_schema)
8
+ end
9
+ end
10
+
11
+ module VirtusWrapper
12
+ extend Wrapper
13
+
14
+ def self.included(base)
15
+ base.send(:include, modularize(base.json_schema))
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+ def json_schema_module
21
+ VirtusWrapper.modularize(json_schema)
22
+ end
23
+ end
24
+
25
+ def self.modularize(json_schema)
26
+ super(json_schema) do
27
+ include ::Virtus.module
28
+
29
+ VirtusWrapper.prepare_schema!(self, self.json_schema, :simple_types)
30
+ def self.included(base)
31
+ super
32
+ VirtusWrapper.prepare_schema!(base, json_schema, :complex_types)
33
+ end
34
+
35
+ def self.extend_object(base)
36
+ class_name = :ComplexTypes
37
+ (const_defined?(class_name) ?
38
+ const_get(class_name) :
39
+ const_set(class_name, Module.new)
40
+ ).tap do |klass|
41
+ klass.send(:include, self) unless klass.include?(self)
42
+ base.extend klass
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def self.prepare_model(ref, field_name, model_class, json_schema)
49
+ model_class.send(:include, modularize(json_schema))
50
+ end
51
+
52
+ def self.add_attribute!(ref, field_name, meta, kind)
53
+ opts = {}
54
+ klass = (kind.is_a?(Class) ? kind : kind.class)
55
+ if kind.is_a?(Class)
56
+ opts[:default] = proc { klass.new } if meta[:required] && kind.include?(VirtusWrapper::Models)
57
+ else
58
+ opts[:default] = proc { kind.class.new }
59
+ end
60
+ ref.attribute field_name, kind, opts
61
+ end
62
+
63
+ def self.collection_superclass
64
+ Array
65
+ end
66
+
67
+ class Array < ::Array
68
+ end
69
+
70
+ module Attribute
71
+ class Array < ::Virtus::Attribute::Collection
72
+ primitive VirtusWrapper::Array
73
+ default Proc.new { |_, attribute| attribute.primitive.new }
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -2,89 +2,8 @@
2
2
 
3
3
  require "virtus"
4
4
 
5
- module JSON
6
- module Schematized
7
- module DSL
8
- def virtus_module
9
- VirtusWrapper.modularize(json_schema)
10
- end
11
- end
12
-
13
- module VirtusWrapper
14
- extend Wrapper
15
-
16
- def self.included(base)
17
- base.send(:include, modularize(base.json_schema))
18
- base.extend ClassMethods
19
- end
20
-
21
- module ClassMethods
22
- def json_schema_module
23
- VirtusWrapper.modularize(json_schema)
24
- end
25
- end
26
-
27
- def self.modularize(json_schema)
28
- super(json_schema) do
29
- include ::Virtus
30
-
31
- VirtusWrapper.prepare_schema!(self, self.json_schema, :simple_types)
32
- def self.included(base)
33
- super
34
- VirtusWrapper.prepare_schema!(base, json_schema, :complex_types)
35
- end
36
-
37
- def self.extend_object(base)
38
- class_name = :ComplexTypes
39
- (const_defined?(class_name) ?
40
- const_get(class_name) :
41
- const_set(class_name, Module.new)
42
- ).tap do |klass|
43
- klass.send(:include, self) unless klass.include?(self)
44
- base.extend klass
45
- end
46
- end
47
- end
48
- end
49
-
50
- def self.prepare_model(ref, field_name, model_class, json_schema)
51
- model_class.send(:include, modularize(json_schema))
52
- end
53
-
54
- def self.add_attribute!(ref, field_name, meta, kind)
55
- opts = {}
56
- klass = (kind.is_a?(Class) ? kind : kind.class)
57
- if kind.is_a?(Class)
58
- opts[:default] = klass.new if meta[:required] && kind.include?(::Virtus)
59
- else
60
- opts[:default] = kind.class.new
61
- end
62
- ref.attribute field_name, kind, opts
63
- end
64
-
65
- def self.collection_superclass
66
- Array
67
- end
68
-
69
- class Array < ::Array
70
- end
71
-
72
- module Attribute
73
- class Array < ::Virtus::Attribute::Array
74
- primitive VirtusWrapper::Array
75
- default primitive.new
76
-
77
- def new_collection
78
- (@primitive || self.class.primitive).new
79
- end
80
-
81
- def self.merge_options(type, options)
82
- merged_options = super
83
- klass = type.is_a?(Class) ? type : type.class
84
- merged_options.merge(:primitive => klass)
85
- end
86
- end
87
- end
88
- end
89
- end
5
+ if ::Virtus.respond_to? :module
6
+ require File.expand_path '../virtus_1_x_x_wrapper.rb', __FILE__
7
+ else
8
+ require File.expand_path '../virtus_0_5_x_wrapper.rb', __FILE__
90
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schematized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
12
+ date: 2014-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -104,17 +104,22 @@ files:
104
104
  - lib/json/schematized/base.rb
105
105
  - lib/json/schematized/basic_wrapper.rb
106
106
  - lib/json/schematized/dsl.rb
107
+ - lib/json/schematized/virtus_0_5_x_wrapper.rb
108
+ - lib/json/schematized/virtus_1_x_x_wrapper.rb
107
109
  - lib/json/schematized/virtus_wrapper.rb
108
110
  - lib/json/schematized/wrapper.rb
109
111
  - script/console
110
112
  - .rspec
113
+ - gemfiles/virtus-0_5_x.gemfile
114
+ - gemfiles/virtus-edge.gemfile
115
+ - gemfiles/virtus-latest.gemfile
111
116
  - spec/fixtures/person.yml
112
117
  - spec/lib/json/schematized/base_spec.rb
113
118
  - spec/lib/json/schematized/basic_wrapper_spec.rb
114
119
  - spec/lib/json/schematized/virtus_wrapper_spec.rb
115
120
  - spec/spec_helper.rb
116
121
  - spec/support/general_shared_excamples.rb
117
- homepage: http://github.com/abril
122
+ homepage: http://github.com/kawamanza
118
123
  licenses: []
119
124
  post_install_message:
120
125
  rdoc_options: []
@@ -134,13 +139,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
139
  version: '0'
135
140
  requirements: []
136
141
  rubyforge_project:
137
- rubygems_version: 1.8.24
142
+ rubygems_version: 1.8.23
138
143
  signing_key:
139
144
  specification_version: 3
140
145
  summary: Object builder based on JSON-Schema
141
146
  test_files:
142
147
  - .rspec
143
148
  - Gemfile
149
+ - gemfiles/virtus-0_5_x.gemfile
150
+ - gemfiles/virtus-edge.gemfile
151
+ - gemfiles/virtus-latest.gemfile
144
152
  - spec/fixtures/person.yml
145
153
  - spec/lib/json/schematized/base_spec.rb
146
154
  - spec/lib/json/schematized/basic_wrapper_spec.rb