simple_sdk_builder 1.0.2 → 1.1.0
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/CHANGELOG.rdoc +3 -0
- data/lib/simple_sdk_builder/resource.rb +12 -6
- data/lib/simple_sdk_builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9a594a981def92fb1b13a39bcbc20a5d8819a45
|
4
|
+
data.tar.gz: 2ee034552cfcc32325686115608355a35fd51a8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54ce9c01786fa81d6faf31c869be975403672ee36fd3133cbbbfedba57ba2d219f537cc05f8869af1c942bee894fa334184cdf52e9eb21f3907f0b1b61a38905
|
7
|
+
data.tar.gz: 6bcf53df2d71e084bf5e6f827662848fae42c164b6c09c154da1fd1b2d2fa01c7d02e0ea6aaa4fe70a09b8c2d82216cdfc0372f38f5aa436a8dbf8db239a4830
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
= Simple SDK Builder
|
2
2
|
|
3
|
+
== Version 1.1.0
|
4
|
+
* Added polymorphic nested attributes. Requires "#{field_name}_type" to be set with name of class that attribute should be constructed with
|
5
|
+
|
3
6
|
== Version 1.0.2
|
4
7
|
* Fixed error handling - allowing custom error handlers for connection/timeout errors and wildcard (*) errors to access the response instead of just an error string.
|
5
8
|
|
@@ -48,8 +48,9 @@ module Resource
|
|
48
48
|
|
49
49
|
def build_attribute(attr, value, options)
|
50
50
|
options = {
|
51
|
-
:
|
52
|
-
:
|
51
|
+
class_name: nil,
|
52
|
+
nested: false,
|
53
|
+
polymorphic: false
|
53
54
|
}.merge(options)
|
54
55
|
|
55
56
|
if options[:nested] && value.is_a?(Array)
|
@@ -61,7 +62,7 @@ module Resource
|
|
61
62
|
end
|
62
63
|
build_attribute(attr, arr, options)
|
63
64
|
elsif options[:nested] && value.is_a?(Hash)
|
64
|
-
class_name = options[:class_name] || guess_class_name(attr)
|
65
|
+
class_name = options[:class_name] || guess_class_name(attr, value, options[:polymorphic])
|
65
66
|
nested_class = eval(class_name)
|
66
67
|
nested_class.new(value)
|
67
68
|
else
|
@@ -69,15 +70,20 @@ module Resource
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
def guess_class_name(attr)
|
73
|
+
def guess_class_name(attr, value, polymorphic = false)
|
73
74
|
namespace = ''
|
74
75
|
class_name = self.class.name
|
75
76
|
if class_name.rindex(':')
|
76
77
|
namespace = class_name[0..class_name.rindex(':')]
|
77
78
|
end
|
78
79
|
attr.chomp!("_attributes")
|
79
|
-
|
80
|
-
|
80
|
+
|
81
|
+
if polymorphic
|
82
|
+
class_name = value.with_indifferent_access[:type]
|
83
|
+
"#{namespace}#{class_name}"
|
84
|
+
else
|
85
|
+
"#{namespace}#{attr.camelize.singularize}"
|
86
|
+
end
|
81
87
|
end
|
82
88
|
|
83
89
|
module ClassMethods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_sdk_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Dawson
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Makes building SDKs for RESTful JSON services easy.
|