rocket_pants 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,11 +62,19 @@ module RocketPants
62
62
  end
63
63
 
64
64
  def self.normalise_object(object, options = {})
65
+ # So we don't use the wrong options / modify them up the chain...
66
+ options = options.dup
67
+
65
68
  # First, prepare the object for serialization.
66
69
  object = normalise_to_serializer object, options
70
+
67
71
  # Convert the object using a standard grape-like lookup chain.
68
- if object.is_a?(Array) || object.is_a?(Set)
69
- object.map { |o| normalise_object o, options }
72
+ if object.is_a?(Array) || object.is_a?(Set) || (options[:each_serializer] && !options[:serializer])
73
+ suboptions = options.dup
74
+ if each_serializer = suboptions.delete(:each_serializer)
75
+ suboptions[:serializer] = each_serializer
76
+ end
77
+ object.map { |o| normalise_object o, suboptions }
70
78
  elsif object.respond_to?(:serializable_hash)
71
79
  object.serializable_hash options
72
80
  elsif object.respond_to?(:as_json)
@@ -79,7 +87,8 @@ module RocketPants
79
87
  def self.normalise_to_serializer(object, options)
80
88
  return object unless RocketPants.serializers_enabled?
81
89
  serializer = options.delete(:serializer)
82
- serializer = object.active_model_serializer if object.respond_to?(:active_model_serializer) && serializer.nil?
90
+ # AMS overrides active_model_serializer, so we ignore it and tell it to go away, generally...
91
+ serializer = object.active_model_serializer if object.respond_to?(:active_model_serializer) && serializer.nil? && !object.is_a?(Array)
83
92
  return object unless serializer
84
93
  SerializerWrapper.new serializer, object
85
94
  end
@@ -127,6 +136,7 @@ module RocketPants
127
136
 
128
137
  def respond_with_object_and_type(object, options, type, singular)
129
138
  pre_process_exposed_object object, type, singular
139
+ options = options.reverse_merge(:singular => singular)
130
140
  options = options.reverse_merge(:compact => true) unless singular
131
141
  meta = expose_metadata metadata_for(object, options, type, singular)
132
142
  render_json({:response => normalise_object(object, options)}.merge(meta), options)
@@ -22,7 +22,7 @@ module RocketPants
22
22
  def version
23
23
  if !instance_variable_defined?(:@version)
24
24
  @version = begin
25
- version = extract_version_string_with_prefix params[:version], request.symbolized_path_parameters[:rp_prefix]
25
+ version = extract_version_string_with_prefix params[:version], request.path_parameters.symbolize_keys[:rp_prefix]
26
26
  version.presence && Integer(version)
27
27
  rescue ArgumentError
28
28
  nil
@@ -51,4 +51,4 @@ module RocketPants
51
51
  end
52
52
 
53
53
  end
54
- end
54
+ end
@@ -19,7 +19,7 @@ module RocketPants
19
19
  defaults[:rp_prefix] = {:text => required_prefix.to_s, :required => true}
20
20
  end
21
21
  versions_regexp = /(#{versions.uniq.join("|")})/
22
- raise ArgumentError, 'please provide atleast one version' if versions.empty?
22
+ raise ArgumentError, 'please provide at least one version' if versions.empty?
23
23
  options = options.deep_merge({
24
24
  :constraints => {:version => versions_regexp},
25
25
  :path => ':version',
@@ -40,4 +40,4 @@ module RocketPants
40
40
  end
41
41
 
42
42
  end
43
- end
43
+ end
@@ -42,7 +42,7 @@ module RocketPants
42
42
  def self.differ
43
43
  return @_differ if instance_variable_defined?(:@_differ)
44
44
  if defined?(RSpec::Support::Differ)
45
- @_differ = RSpec::Expectations::Differ
45
+ @_differ = RSpec::Support::Differ.new
46
46
  elsif defined?(RSpec::Expectations::Differ)
47
47
  @_differ = RSpec::Expectations::Differ.new
48
48
  else
@@ -126,4 +126,4 @@ module RocketPants
126
126
 
127
127
 
128
128
  end
129
- end
129
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocket_pants
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
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: 2015-04-30 00:00:00.000000000 Z
12
+ date: 2015-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack