acts_as_api 0.1.7 → 0.1.10

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.
@@ -1,3 +1,8 @@
1
+ === 0.1.10 2010-07-23
2
+
3
+ * More Bugfixes. When you want to render an Array of records (e.g. from MyRecord.all)
4
+ make sure you pass the :root options to render_as_api - in case it will return an empty array
5
+
1
6
  === 0.1.7 2010-07-05
2
7
 
3
8
  * Fixed bug with multi-word models.
@@ -16,7 +16,7 @@ require "acts_as_api/array"
16
16
  # acts_as_api uses the default serializers of your rails app and doesn't
17
17
  # force you into more dependencies.
18
18
  module ActsAsApi
19
- VERSION = '0.1.7'
19
+ VERSION = '0.1.10'
20
20
 
21
21
  # The accepted response formats
22
22
  # Default is +[:xml, :json]+
@@ -27,6 +27,15 @@ module ActsAsApi
27
27
  # with the name of the model.
28
28
  ADD_ROOT_NODE_FOR = [:json]
29
29
 
30
+ # Holds formats that should be dasherized
31
+ DASHERIZE_FOR = [:xml]
32
+
33
+ # The default name of a root node of a response
34
+ # if no root paramter is passed in render_for_api
35
+ # and the gem is not able to determine a root name
36
+ # automatically
37
+ DEFAULT_ROOT = :record
38
+
30
39
  end
31
40
 
32
41
  # Attach ourselves to active record
@@ -28,33 +28,41 @@ module ActsAsApi
28
28
  output_params = render_options
29
29
 
30
30
 
31
- # set the name of the root node - pluralize for arrays
32
- if api_model.is_a?(Array)
33
- api_root_name = api_model.respond_to?(:model_name) ? api_model.model_name.singular.pluralize : api_model.first.class.model_name.singular.pluralize
31
+ api_root_name = nil
32
+
33
+ if !output_params[:root].nil?
34
+
35
+ api_root_name = output_params[:root].to_s
36
+
37
+ elsif api_model.respond_to?(:model_name)
38
+ api_root_name = api_model.model_name
39
+ elsif api_model.is_a?(Array) && !api_model.empty? && api_model.first.class.respond_to?(:model_name)
40
+ api_root_name = api_model.first.class.model_name
41
+ elsif api_model.class.respond_to?(:model_name)
42
+ api_root_name = api_model.class.model_name
34
43
  else
35
- api_root_name = api_model.class.model_name.singular
44
+ api_root_name = ActsAsApi::DEFAULT_ROOT.to_s
36
45
  end
37
46
 
38
- api_root_name.dasherize if api_format.to_s == :xml.to_s
47
+ api_root_name = api_root_name.underscore.tr('/', '_')
39
48
 
40
- # Does not work
41
- #api_root_name.camelize if api_format.to_s == :json.to_s
49
+ if api_model.is_a?(Array)
50
+ api_root_name = api_root_name.pluralize
51
+ end
42
52
 
43
- output_params[:root] ||= api_root_name
53
+ api_root_name = api_root_name.dasherize if ActsAsApi::DASHERIZE_FOR.include? api_format.to_sym
44
54
 
45
-
55
+ output_params[:root] = api_root_name
46
56
 
47
57
  #output_params[:root] = output_params[:root].camelize if render_options.has_key?(:camelize) && render_options[:camelize]
48
58
  #output_params[:root] = output_params[:root].dasherize if !render_options.has_key?(:dasherize) || render_options[:dasherize]
49
59
 
50
-
51
60
  api_response = api_model.as_api_response
52
61
 
53
62
  if ActsAsApi::ADD_ROOT_NODE_FOR.include? api_format
54
63
  api_response = { api_root_name.to_sym => api_response}
55
64
  end
56
65
 
57
-
58
66
  # create the Hash as response
59
67
  output_params[api_format] = api_response
60
68
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 7
9
- version: 0.1.7
8
+ - 10
9
+ version: 0.1.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Christian B\xC3\xA4uerlein"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-05 00:00:00 +02:00
17
+ date: 2010-07-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency