restfully 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,7 +5,7 @@ An attempt at dynamically providing "clever" wrappers on top of RESTful APIs tha
5
5
  Alpha work.
6
6
 
7
7
  == Installation
8
- $ gem install restfully
8
+ $ gem install restfully --source http://gemcutter.org
9
9
 
10
10
  == Usage
11
11
  === Command line
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/bin/restfully CHANGED
@@ -6,7 +6,6 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
6
6
  require 'restfully'
7
7
  require 'optparse'
8
8
  require 'logger'
9
- require 'pp'
10
9
  require 'yaml'
11
10
 
12
11
 
data/lib/restfully.rb CHANGED
@@ -12,7 +12,7 @@ require 'restfully/collection'
12
12
 
13
13
 
14
14
  module Restfully
15
- VERSION = "0.3.1"
15
+ VERSION = "0.3.2"
16
16
  class << self
17
17
  attr_accessor :adapter
18
18
  end
@@ -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
- def inspect(options = {:space => "\t"})
103
- output = "#<#{self.class}:0x#{self.object_id.to_s(16)}"
104
- if loaded?
105
- output += "\n#{options[:space]}------------ META ------------"
106
- output += "\n#{options[:space]}@uri: #{uri.inspect}"
107
- output += "\n#{options[:space]}@offset: #{offset.inspect}"
108
- output += "\n#{options[:space]}@total: #{total.inspect}"
109
- @associations.each do |title, assoc|
110
- output += "\n#{options[:space]}@#{title}: #{assoc.class.name}"
111
- end
112
- unless @attributes.empty?
113
- output += "\n#{options[:space]}------------ PROPERTIES ------------"
114
- @attributes.each do |key, value|
115
- output += "\n#{options[:space]}#{key.inspect} => #{value.inspect}"
116
- end
117
- end
118
- unless self.empty?
119
- output += "\n#{options[:space]}------------ ITEMS ------------"
120
- self.each do |value|
121
- output += "\n#{options[:space]}#{value.class.name}"
122
- end
123
- end
124
- end
125
- output += ">"
126
- end
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)
@@ -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, :uid, :type
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
- def inspect(options = {:space => "\t"})
73
- output = "#<#{self.class}:0x#{self.object_id.to_s(16)}"
74
- if loaded?
75
- output += "\n#{options[:space]}------------ META ------------"
76
- output += "\n#{options[:space]}@uri: #{uri.inspect}"
77
- output += "\n#{options[:space]}@uid: #{uid.inspect}"
78
- output += "\n#{options[:space]}@type: #{type.inspect}"
79
- @associations.each do |title, assoc|
80
- output += "\n#{options[:space]}@#{title}: #{assoc.class.name}"
81
- end
82
- unless @attributes.empty?
83
- output += "\n#{options[:space]}------------ PROPERTIES ------------"
84
- @attributes.each do |key, value|
85
- output += "\n#{options[:space]}#{key.inspect} => #{value.inspect}"
86
- end
87
- end
88
- end
89
- output += ">"
90
- end
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.1"
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-10-27}
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}
@@ -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.uid}.sort.should == ["bordeaux", "grenoble", "lille", "lyon", "nancy", "orsay", "rennes", "sophia", "toulouse"]
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').uid.should == 'rennes'
93
- collection.by_uid('rennes').type.should == 'site'
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
@@ -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.uid.should == 'rennes'
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.1
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-10-27 00:00:00 +01:00
12
+ date: 2009-11-02 00:00:00 +01:00
13
13
  default_executable: restfully
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency