restrack 1.6.8 → 1.6.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/restrack.rb CHANGED
@@ -22,3 +22,8 @@ end
22
22
 
23
23
  include HTTPStatus
24
24
  include ActiveSupport::Inflector
25
+
26
+ # TODO: configurable list of params to strip before logging
27
+ # TODO: update README
28
+ # TODO: markdown to html generator
29
+ # TODO: async plugin
@@ -1,7 +1,7 @@
1
1
  module RESTRack
2
2
  # The ResourceRequest class handles all incoming requests.
3
3
  class ResourceRequest
4
- attr_reader :request, :request_id, :params, :post_params, :get_params, :active_controller
4
+ attr_reader :request, :request_id, :params, :post_params, :get_params, :active_controller, :headers
5
5
  attr_accessor :mime_type, :url_chain
6
6
 
7
7
  # Initialize the ResourceRequest by assigning a request_id and determining the path, format, and controller of the resource.
@@ -46,13 +46,13 @@ module RESTRack
46
46
  @post_params = parse_body( @request )
47
47
  @get_params = parse_query_string( @request )
48
48
  @params = {}
49
- # TODO: symbolize!
50
49
  if @post_params.respond_to?(:merge)
51
50
  @params = @post_params.merge( @get_params )
52
51
  else
53
52
  @params = @get_params
54
53
  end
55
- RESTRack.log.debug 'combined params: ' + @params.inspect
54
+ @params.symbolize!
55
+ log_request_params(@params)
56
56
 
57
57
  # Pull first controller from URL
58
58
  @active_resource_name = @url_chain.shift
@@ -68,6 +68,10 @@ module RESTRack
68
68
  @active_controller = instantiate_controller( @active_resource_name )
69
69
  end
70
70
 
71
+ def log_request_params(params_hash)
72
+ RESTRack.request_log.debug 'Combined Request Params: ' + params_hash.inspect
73
+ end
74
+
71
75
  # Call the next entity in the path stack.
72
76
  # Method called by controller relationship methods.
73
77
  def call_controller(resource_name)
@@ -69,6 +69,37 @@ class ARFormattedError < String
69
69
  end
70
70
  end
71
71
 
72
+ class Hash
73
+ def symbolize!
74
+ new_keys = {}
75
+ self.each do |key,val|
76
+ if val.is_a? Hash or val.is_a? Array
77
+ val.symbolize!
78
+ end
79
+ unless key.is_a? Symbol or not key.respond_to?(:to_sym)
80
+ new_keys[key.to_sym] = self[key]
81
+ self.delete(key)
82
+ end
83
+ end
84
+ self.merge!(new_keys)
85
+ end
86
+
87
+ def symbolize
88
+ self_clone = self.clone
89
+ new_keys = {}
90
+ self_clone.each do |key,val|
91
+ if val.is_a? Hash or val.is_a? Array
92
+ val = val.symbolize
93
+ end
94
+ unless key.is_a? Symbol or not key.respond_to?(:to_sym)
95
+ new_keys[key.to_sym] = val
96
+ self_clone.delete(key)
97
+ end
98
+ end
99
+ return self_clone.merge(new_keys)
100
+ end
101
+ end
102
+
72
103
  # We will support ".text" as an extension
73
104
  MIME::Types['text/plain'][0].extensions << 'text'
74
105
  MIME::Types.index_extensions( MIME::Types['text/plain'][0] )
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.6.8"
2
+ VERSION = "1.6.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8
4
+ version: 1.6.9
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: 2012-11-14 00:00:00.000000000 Z
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack