ananke 2.0.0 → 2.0.1

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.
@@ -70,20 +70,18 @@ module Sinatra
70
70
  app.helpers Ananke::Helpers
71
71
  end
72
72
 
73
- attr_reader :resource_name, :resource_id, :resource_items, :resource_link_to, :resource_classes, :resource_mime, :resource_remove_empty
73
+ attr_reader :resource_name, :resource_id, :resource_link_to, :resource_classes, :resource_mime, :resource_remove_empty
74
74
  def resource_link_self?() @resource_link_self end
75
75
 
76
76
  def make_resource(name, options = {})
77
77
  reset!
78
78
  options[:id] ||= :id
79
- options[:items] ||= :items
80
79
  options[:link_self] = options.has_key?(:link_self) ? options[:link_self] : true
81
80
  options[:link_to] ||= []
82
81
  options[:classes] ||= []
83
82
 
84
83
  @resource_name = name
85
84
  @resource_id = options[:id]
86
- @resource_items = options[:items]
87
85
  @resource_link_self = options[:link_self]
88
86
  @resource_link_to = options[:link_to]
89
87
  @resource_classes ||= []
@@ -123,24 +121,23 @@ module Sinatra
123
121
  res = {
124
122
  :name => resource_name,
125
123
  :id => resource_id,
126
- :items => resource_items,
127
124
  :link_self => resource_link_self?,
128
125
  :link_to => resource_link_to,
129
126
  :classes => resource_classes,
130
127
  :remove_empty => resource_remove_empty
131
128
  }
132
129
  block_params = block.parameters.collect {|p| p[1]}
133
- path = "#{path}/:#{block_params[0]}" if [:get,:put,:delete].include?(type) && block_params.length >= 1 && path != ":#{block_params[0]}"
130
+ path = "#{path}/:#{block_params[0]}" if [:get,:put,:delete].include?(type) && block_params.length == 1 && path != ":#{block_params[0]}"
134
131
  method(type).call "/#{resource_name}/#{path}", options, do
135
132
  inject_app(res[:classes])
136
133
  input_params = collect_input_params(params, &block)
137
134
 
138
135
  result = instance_exec(*input_params, &block)
139
- result = Serialize.to_a(result, :remove_empty => res[:remove_empty])
140
- result = result.empty? && {} || {res[:items] => Serialize.to_h(result, :remove_empty => res[:remove_empty])}
136
+ result = Serialize.to_h(result, :remove_empty => res[:remove_empty])
137
+ result = [result] unless result.respond_to? :each
141
138
 
142
139
  #inject links
143
- result[res[:items]].each do |item|
140
+ (result.class == Array && result || [result]).each do |item|
144
141
  next unless item.respond_to?(:has_key?) && item.has_key?(res[:id])
145
142
  links = []
146
143
  links << {:rel => :self, :href => "/#{res[:name]}/#{item[res[:id]]}"} if res[:link_self]
@@ -1,3 +1,3 @@
1
1
  module Ananke
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
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.0
5
+ version: 2.0.1
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-13 00:00:00 Z
13
+ date: 2011-09-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colored