ananke 2.0.2 → 2.0.3

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.
@@ -39,12 +39,13 @@ module Sinatra
39
39
  end
40
40
 
41
41
  module Helpers
42
- def collect_input_params(params, &block)
42
+ def collect_input_params(params, optional = [], &block)
43
43
  block_params = block.parameters.collect {|p| p[1]}
44
44
  block_params.collect do |param|
45
- error(400, "Missing parameter - #{param}") unless params.has_key? param.to_s
45
+ error(400, "Missing parameter - #{param}") if !params.has_key?(param.to_s) && !optional.include?(param)
46
46
  value = params[param]
47
47
  case
48
+ when value.nil?; value
48
49
  when value.to_i.to_s == value; value.to_i
49
50
  when value.to_f.to_s == value; value.to_f
50
51
  else value
@@ -126,11 +127,15 @@ module Sinatra
126
127
  :classes => resource_classes,
127
128
  :remove_empty => resource_remove_empty
128
129
  }
130
+ id_param = options.delete(:id)
131
+ optional = options.delete(:optional) || []
129
132
  block_params = block.parameters.collect {|p| p[1]}
130
- path = "#{path}/:#{block_params[0]}" if [:get,:put,:delete].include?(type) && block_params.length >= 1 && path != ":#{block_params[0]}"
133
+ if [:get,:put,:delete].include?(type)
134
+ path = "#{path}/:#{block_params[0]}" if (block_params.length == 1 && path != ":#{block_params[0]}") || id_param
135
+ end
131
136
  method(type).call "/#{resource_name}/#{path}", options, do
132
137
  inject_app(res[:classes])
133
- input_params = collect_input_params(params, &block)
138
+ input_params = collect_input_params(params, optional, &block)
134
139
 
135
140
  result = instance_exec(*input_params, &block)
136
141
  result = Serialize.to_h(result, :remove_empty => res[:remove_empty])
@@ -1,3 +1,3 @@
1
1
  module Ananke
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ananke
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.2
5
+ version: 2.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andries Coetzee
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-15 00:00:00 Z
13
+ date: 2011-09-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colored