shapeable 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c95227cc1ac36a8fbaa29cd421a90984740fa49
4
- data.tar.gz: ebe50c0055ffa8595085b8f3114e9ac7808a49d1
3
+ metadata.gz: 4ed1e8139b673601f51a5a4a95830670945710d4
4
+ data.tar.gz: 013a597aba452cc63d267909298c84e7ee027449
5
5
  SHA512:
6
- metadata.gz: 873f0e823c9cea191193691a3aa6004a1085b5a306b3cc3425ded7de174e8a3647a90817bd4a9c1ba35e2ab80001a2b0bf03f86d5c7ce1f377c886e068b8afb2
7
- data.tar.gz: b465a882b86f93fecf29f1e58e7d98af65ff59d47ceb4f867ef5c94ff0c326eaf2890dd04e3a806084ae655567df2461ffffda71060b9a482991a7c7428f9f36
6
+ metadata.gz: 7e3babc9c59f8fb1ee8a8e9a6825d83ff29f6afc93ef9ef546a526170e2cd728cd33d3b3bd52ce4136294eb62701486d9fad02ba5330e9bda3f19be8c3ba5b54
7
+ data.tar.gz: 4990746ce0a05398bf8ab340147fc1158fee3a92c5215d85bcfb1f659a6ed452e646f89235f1bf55617d732bd3f58b1771c3f61b0cc8a36777f829ae9ddab661
@@ -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, "specify a default shape" unless default_shape
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
 
@@ -1,3 +1,3 @@
1
1
  module Shapeable
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shapeable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn O'Mara