restful_serializer 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/restful.rb +4 -2
- data/lib/restful/serializer.rb +14 -4
- data/lib/restful/version.rb +1 -1
- data/spec/serializer_spec.rb +21 -1
- data/spec/spec_helper.rb +4 -2
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ If the model has a name column, it will be used to describe the resource.
|
|
6
6
|
|
7
7
|
This library does not attempt to provide href info for transitions, or deal much with questions of authorization beyond what is specified in the serialization configuration lines. It assumes that these issues would be resolved in the controller. It assumes standard naming conventions for routes.
|
8
8
|
|
9
|
-
|
9
|
+
Tested with Rails 2.3.11. Requires the Rails framework to be loaded.
|
10
10
|
|
11
11
|
== Example
|
12
12
|
|
data/lib/restful.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# This file is part of restful_serializer. Copyright 2011 Joshua Partlow. This is free software, see the LICENSE file for details.
|
2
|
-
require 'active_support'
|
3
|
-
require 'restful/serializer'
|
4
2
|
|
5
3
|
# This library is used to decorate ActiveRecord with methods to assist in generating
|
6
4
|
# Restful content for Web Services.
|
@@ -119,6 +117,10 @@ require 'restful/serializer'
|
|
119
117
|
# not been configured as arrays, then deep merge would have overwritten rather than merging
|
120
118
|
# them. This could probably be adjusted with a closer look into the deep_merge docs.)
|
121
119
|
module Restful
|
120
|
+
# Requiring Serializer (and hence action_controller for UrlWriter) was interferring with
|
121
|
+
# route generation somehow, so instead we are letting it autoload if used.
|
122
|
+
autoload :Serializer, 'restful/serializer'
|
123
|
+
|
122
124
|
# Route prefix for api calls.
|
123
125
|
mattr_accessor :api_prefix
|
124
126
|
|
data/lib/restful/serializer.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# This file is part of restful_serializer. Copyright 2011 Joshua Partlow. This is free software, see the LICENSE file for details.
|
2
|
-
require 'active_record'
|
3
|
-
require 'action_controller'
|
4
2
|
require 'deep_merge'
|
5
3
|
|
6
4
|
module Restful
|
5
|
+
|
7
6
|
module UrlForHelpers
|
8
7
|
|
9
|
-
# Used to construct and attempt to call named routes
|
8
|
+
# Used to construct and attempt to call named routes by providing resource
|
10
9
|
# strings out of which a named route method name will be constructed:
|
11
10
|
#
|
12
11
|
# Options:
|
@@ -37,7 +36,18 @@ module Restful
|
|
37
36
|
include ActionController::UrlWriter
|
38
37
|
include UrlForHelpers
|
39
38
|
attr_accessor :subject, :base_klass, :klass, :options, :shallow
|
40
|
-
|
39
|
+
|
40
|
+
class << self
|
41
|
+
|
42
|
+
alias_method :serializer_default_url_options=, :default_url_options=
|
43
|
+
# Set ActionController::UrlWriter.default_url_options for all Serializer
|
44
|
+
# actions.
|
45
|
+
def default_url_options=(options)
|
46
|
+
self.serializer_default_url_options = options
|
47
|
+
Association.default_url_options = options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
41
51
|
def initialize(subject, *args)
|
42
52
|
self.subject = subject
|
43
53
|
|
data/lib/restful/version.rb
CHANGED
data/spec/serializer_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
|
+
ActionController::Routing::Routes.clear!
|
3
4
|
ActionController::Routing::Routes.draw do |map|
|
4
5
|
map.resources :foos
|
5
6
|
map.prefix_foo 'prefix/foos/:id', :controller => 'foos', :action => 'show'
|
@@ -11,7 +12,6 @@ ActionController::Routing::Routes.draw do |map|
|
|
11
12
|
end
|
12
13
|
|
13
14
|
describe Restful::Serializer do
|
14
|
-
|
15
15
|
class Foo < ActiveRecord::Base
|
16
16
|
has_many :bars
|
17
17
|
def fancy_name
|
@@ -77,6 +77,18 @@ describe Restful::Serializer do
|
|
77
77
|
Restful.model_configuration = {}
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should not interfere with resource route generation" do
|
81
|
+
ActionController::Routing::Routes.routes.size.should == 30
|
82
|
+
by_method = ActionController::Routing::Routes.routes.group_by { |r|
|
83
|
+
r.conditions[:method]
|
84
|
+
}
|
85
|
+
by_method[:get].size.should == 4 * 4
|
86
|
+
by_method[:put].size.should == 4
|
87
|
+
by_method[:post].size.should == 4
|
88
|
+
by_method[:delete].size.should == 4
|
89
|
+
by_method[nil].size.should == 2
|
90
|
+
end
|
91
|
+
|
80
92
|
it "should require a subject" do
|
81
93
|
lambda { Restful::Serializer.new }.should raise_error(ArgumentError)
|
82
94
|
Restful::Serializer.new('foo').should be_kind_of(Restful::Serializer)
|
@@ -87,6 +99,14 @@ describe Restful::Serializer do
|
|
87
99
|
rs.klass.should == 'foo'
|
88
100
|
end
|
89
101
|
|
102
|
+
it "should set default url options" do
|
103
|
+
Restful::Serializer.default_url_options.should == { :host => 'test.org' }
|
104
|
+
Restful::Association.default_url_options.should == { :host => 'test.org' }
|
105
|
+
Restful::Serializer.default_url_options = opts = { :host => 'foo' }
|
106
|
+
Restful::Serializer.default_url_options.should == opts
|
107
|
+
Restful::Association.default_url_options.should == opts
|
108
|
+
end
|
109
|
+
|
90
110
|
it "should serialize" do
|
91
111
|
@foo.save!
|
92
112
|
rs = Restful::Serializer.new(@foo)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'rubygems'
|
4
|
-
require '
|
4
|
+
require 'action_controller'
|
5
|
+
require 'database'
|
6
|
+
|
5
7
|
require 'spec'
|
6
8
|
require 'spec/autorun'
|
7
9
|
require 'pp'
|
8
10
|
|
9
|
-
require '
|
11
|
+
require 'restful'
|
10
12
|
|
11
13
|
#class TestLogger
|
12
14
|
# [:debug, :info, :warn, :error].each do |m|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Partlow
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-12 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
178
|
requirements: []
|
179
179
|
|
180
180
|
rubyforge_project:
|
181
|
-
rubygems_version: 1.
|
181
|
+
rubygems_version: 1.6.2
|
182
182
|
signing_key:
|
183
183
|
specification_version: 3
|
184
184
|
summary: Helps with serializing activerecord instances as Restful resources.
|