restfully 0.3.1 → 0.3.2
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.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/bin/restfully +0 -1
- data/lib/restfully.rb +1 -1
- data/lib/restfully/collection.rb +34 -25
- data/lib/restfully/resource.rb +23 -22
- data/restfully.gemspec +2 -2
- data/spec/collection_spec.rb +3 -3
- data/spec/resource_spec.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/bin/restfully
CHANGED
data/lib/restfully.rb
CHANGED
data/lib/restfully/collection.rb
CHANGED
@@ -27,6 +27,14 @@ module Restfully
|
|
27
27
|
@state = :unloaded
|
28
28
|
end
|
29
29
|
|
30
|
+
def [](key)
|
31
|
+
if key.is_a? Symbol
|
32
|
+
by_uid(key.to_s)
|
33
|
+
else
|
34
|
+
super(key)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
def method_missing(method, *args)
|
31
39
|
load
|
32
40
|
if association = @associations[method.to_s]
|
@@ -99,31 +107,32 @@ module Restfully
|
|
99
107
|
@associations.has_key?(method.to_s) || super(method, *args)
|
100
108
|
end
|
101
109
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
110
|
+
# Removed: use `y resource` to get pretty output
|
111
|
+
# def inspect(options = {:space => "\t"})
|
112
|
+
# output = "#<#{self.class}:0x#{self.object_id.to_s(16)}"
|
113
|
+
# if loaded?
|
114
|
+
# output += "\n#{options[:space]}------------ META ------------"
|
115
|
+
# output += "\n#{options[:space]}@uri: #{uri.inspect}"
|
116
|
+
# output += "\n#{options[:space]}@offset: #{offset.inspect}"
|
117
|
+
# output += "\n#{options[:space]}@total: #{total.inspect}"
|
118
|
+
# @associations.each do |title, assoc|
|
119
|
+
# output += "\n#{options[:space]}@#{title}: #{assoc.class.name}"
|
120
|
+
# end
|
121
|
+
# unless @attributes.empty?
|
122
|
+
# output += "\n#{options[:space]}------------ PROPERTIES ------------"
|
123
|
+
# @attributes.each do |key, value|
|
124
|
+
# output += "\n#{options[:space]}#{key.inspect} => #{value.inspect}"
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
# unless self.empty?
|
128
|
+
# output += "\n#{options[:space]}------------ ITEMS ------------"
|
129
|
+
# self.each do |value|
|
130
|
+
# output += "\n#{options[:space]}#{value.class.name}"
|
131
|
+
# end
|
132
|
+
# end
|
133
|
+
# end
|
134
|
+
# output += ">"
|
135
|
+
# end
|
127
136
|
|
128
137
|
protected
|
129
138
|
def define_link(link)
|
data/lib/restfully/resource.rb
CHANGED
@@ -7,7 +7,7 @@ module Restfully
|
|
7
7
|
class Resource < DelegateClass(Hash)
|
8
8
|
|
9
9
|
undef :type if self.respond_to? :type
|
10
|
-
attr_reader :uri, :session, :state, :raw, :associations
|
10
|
+
attr_reader :uri, :session, :state, :raw, :associations
|
11
11
|
|
12
12
|
def initialize(uri, session, options = {})
|
13
13
|
options = options.symbolize_keys
|
@@ -46,8 +46,8 @@ module Restfully
|
|
46
46
|
(raw['links'] || []).each{|link| define_link(Link.new(link))}
|
47
47
|
raw.each do |key, value|
|
48
48
|
case key
|
49
|
-
when "uid", "type"
|
50
|
-
instance_variable_set "@#{key}".to_sym, value
|
49
|
+
# when "uid", "type"
|
50
|
+
# instance_variable_set "@#{key}".to_sym, value
|
51
51
|
when 'links' then next
|
52
52
|
else
|
53
53
|
case value
|
@@ -69,25 +69,26 @@ module Restfully
|
|
69
69
|
@associations.has_key?(method.to_s) || super(method, *args)
|
70
70
|
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
72
|
+
# Removed: use `y resource` to get pretty output
|
73
|
+
# def inspect(options = {:space => "\t"})
|
74
|
+
# output = "#<#{self.class}:0x#{self.object_id.to_s(16)}"
|
75
|
+
# if loaded?
|
76
|
+
# output += "\n#{options[:space]}------------ META ------------"
|
77
|
+
# output += "\n#{options[:space]}@uri: #{uri.inspect}"
|
78
|
+
# output += "\n#{options[:space]}@uid: #{uid.inspect}"
|
79
|
+
# output += "\n#{options[:space]}@type: #{type.inspect}"
|
80
|
+
# @associations.each do |title, assoc|
|
81
|
+
# output += "\n#{options[:space]}@#{title}: #{assoc.class.name}"
|
82
|
+
# end
|
83
|
+
# unless @attributes.empty?
|
84
|
+
# output += "\n#{options[:space]}------------ PROPERTIES ------------"
|
85
|
+
# @attributes.each do |key, value|
|
86
|
+
# output += "\n#{options[:space]}#{key.inspect} => #{value.inspect}"
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
# output += ">"
|
91
|
+
# end
|
91
92
|
|
92
93
|
protected
|
93
94
|
def define_link(link)
|
data/restfully.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{restfully}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril Rohr"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-02}
|
13
13
|
s.default_executable = %q{restfully}
|
14
14
|
s.description = %q{Experimental code for auto-generation of wrappers on top of RESTful APIs that follow HATEOAS principles and provide OPTIONS methods and/or Allow headers.}
|
15
15
|
s.email = %q{cyril.rohr@gmail.com}
|
data/spec/collection_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Collection do
|
|
8
8
|
end
|
9
9
|
it "should be enumerable" do
|
10
10
|
@collection.length.should == 9
|
11
|
-
@collection.map{|site| site
|
11
|
+
@collection.map{|site| site["uid"]}.sort.should == ["bordeaux", "grenoble", "lille", "lyon", "nancy", "orsay", "rennes", "sophia", "toulouse"]
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should have a :total method" do
|
@@ -89,8 +89,8 @@ describe Collection do
|
|
89
89
|
collection.load
|
90
90
|
collection.should be_loaded
|
91
91
|
collection.uri.should == "uri"
|
92
|
-
collection.by_uid('rennes')
|
93
|
-
collection.by_uid('rennes')
|
92
|
+
collection.by_uid('rennes')["uid"].should == 'rennes'
|
93
|
+
collection.by_uid('rennes')["type"].should == 'site'
|
94
94
|
collection.by_uid.keys.should =~ ['rennes', 'lille', 'bordeaux', 'nancy', 'sophia', 'toulouse', 'lyon', 'grenoble', 'orsay']
|
95
95
|
collection.by_uid('rennes', 'bordeaux').length.should == 2
|
96
96
|
end
|
data/spec/resource_spec.rb
CHANGED
@@ -122,7 +122,7 @@ describe Resource do
|
|
122
122
|
resource.load
|
123
123
|
resource['whatever'].should == 'whatever'
|
124
124
|
resource.uri.should == 'uri'
|
125
|
-
resource
|
125
|
+
resource["uid"].should == 'rennes'
|
126
126
|
resource['an_array'].should be_a(SpecialArray)
|
127
127
|
resource['an_array'].should == [1,2,3]
|
128
128
|
lambda{resource.clusters}.should raise_error(NoMethodError)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restfully
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Rohr
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-02 00:00:00 +01:00
|
13
13
|
default_executable: restfully
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|