moonrope 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1be661422027acf61678bd7b6a73932376b53ec3
4
- data.tar.gz: 3ea06c9d8c46916c81b833d6c0bd7328e7886580
3
+ metadata.gz: 81c19996325ee4342d9c027d043e03dc15dbf4b1
4
+ data.tar.gz: 6a5859ecd39d546385894fd3d114aee48b0dd166
5
5
  SHA512:
6
- metadata.gz: adf31e337346e9f3013a1d89b6583ef1dc87a0fd771c21aaf4c871460e31abdc6f95c839922df56cc8eaaac91dec05b60fe15f3ad99ab0eff86cde9b171155a7
7
- data.tar.gz: 3256a19d2938b43720bdf9ea95ffac7f5f86704c9acffce1977c7f16591ea0eacfbc1de49b96fa3b5a0782fba49955e52a6407c75da60efbbb71781fdb219791
6
+ metadata.gz: c8795f460fcbb66d4c93acd896fcb2a1e15b73650f3e824069366fdb3d8fd3a6699a3fce21f2b76c41387070d9cd52730f34b94984750880258783c6644e2ec1
7
+ data.tar.gz: 02fc479ae9b0c7609935605c7296eab781eaf3d8d82ced6e826f94b24fc965fca1ce5ba8f1a44926772ac79b36d4df21811b837501ab97caecc5f690b8abe4a8
@@ -119,17 +119,31 @@ module Moonrope
119
119
  # @param object [Object] the object to pass through the structure
120
120
  # @param options [Hash] options to pass to the strucutre hash generator
121
121
  #
122
- def structure(structure_name, object, options = {})
123
- if object
124
- structure = structure_for(structure_name)
125
- if structure.is_a?(Moonrope::Structure)
126
- structure.hash(object, options.merge(:request => @request))
127
- else
128
- raise Moonrope::Errors::Error, "No structure found named '#{structure_name}'"
129
- end
122
+ def structure(structure_name_or_object, object_or_options = {}, options_if_structure_name = {})
123
+
124
+ if structure_name_or_object.is_a?(Symbol) || structure_name_or_object.is_a?(String) || structure_name_or_object.is_a?(Moonrope::Structure)
125
+ structure_name = structure_name_or_object
126
+ object = object_or_options
127
+ options = options_if_structure_name
128
+ elsif structure_name_or_object.class.name.respond_to?(:underscore)
129
+ structure_name = structure_name_or_object.class.name.underscore.to_sym
130
+ object = structure_name_or_object
131
+ options = object_or_options
130
132
  else
131
- nil
133
+ raise Moonrope::Errors::Error, "Could not determine structure name"
132
134
  end
135
+
136
+ if object.nil?
137
+ return nil
138
+ end
139
+
140
+ structure = structure_for(structure_name)
141
+
142
+ unless structure.is_a?(Moonrope::Structure)
143
+ raise Moonrope::Errors::Error, "No structure found named '#{structure_name}'"
144
+ end
145
+
146
+ structure.hash(object, options.merge(:request => @request))
133
147
  end
134
148
 
135
149
  #
@@ -1,3 +1,3 @@
1
1
  module Moonrope
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moonrope
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke