shapeable 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shapeable.rb +4 -4
- data/lib/shapeable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed1e8139b673601f51a5a4a95830670945710d4
|
4
|
+
data.tar.gz: 013a597aba452cc63d267909298c84e7ee027449
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3babc9c59f8fb1ee8a8e9a6825d83ff29f6afc93ef9ef546a526170e2cd728cd33d3b3bd52ce4136294eb62701486d9fad02ba5330e9bda3f19be8c3ba5b54
|
7
|
+
data.tar.gz: 4990746ce0a05398bf8ab340147fc1158fee3a92c5215d85bcfb1f659a6ed452e646f89235f1bf55617d732bd3f58b1771c3f61b0cc8a36777f829ae9ddab661
|
data/lib/shapeable.rb
CHANGED
@@ -7,19 +7,18 @@ module Shapeable
|
|
7
7
|
normalize_shapeable_options(opts)
|
8
8
|
acts_as_shapeable_opts = opts || {}
|
9
9
|
|
10
|
-
define_method(:shape) do |opts|
|
10
|
+
define_method(:shape) do |opts={}|
|
11
11
|
opts = acts_as_shapeable_opts.merge(opts)
|
12
12
|
default_shape = opts[:default_shape]
|
13
13
|
default_version = opts[:default_version]
|
14
14
|
path = opts[:path]
|
15
|
-
raise ArgumentError, "
|
16
|
-
raise ArgumentError, "specify a default version" unless default_version
|
17
|
-
raise ArgumentError, "specify a path" unless path
|
15
|
+
raise ArgumentError, "Specify a path" unless path
|
18
16
|
resource = path.name.split('::').last.constantize
|
19
17
|
if request.accept
|
20
18
|
version_str = request.accept[/version\s?=\s?(\d+)/, 1]
|
21
19
|
version = version_str.nil? ? default_version : version_str.to_i
|
22
20
|
shape = request.accept[/shape\s?=\s?(\w+)/, 1] || default_shape
|
21
|
+
raise UnresolvedShapeError, "Unable to resolve shape. Try specifying a default version and shape" unless version && shape
|
23
22
|
begin
|
24
23
|
serializer = path.const_get("V#{version}").const_get("#{resource}#{shape.camelize}Serializer")
|
25
24
|
rescue NameError
|
@@ -39,6 +38,7 @@ module Shapeable
|
|
39
38
|
end
|
40
39
|
|
41
40
|
class InvalidShapeError < NameError; end
|
41
|
+
class UnresolvedShapeError < Exception; end
|
42
42
|
|
43
43
|
end
|
44
44
|
|
data/lib/shapeable/version.rb
CHANGED