sporkd-couchrest 0.30 → 0.31

Sign up to get free protection for your applications and to get access to all the features.
data/history.txt CHANGED
@@ -1,3 +1,20 @@
1
+ == 0.40
2
+
3
+ === Notes
4
+
5
+ This release slightly modifies the API and if you were using a previous version of CouchRest,
6
+ you will need to make the following modifications.
7
+
8
+
9
+
10
+ * Major enhancements
11
+
12
+ *
13
+
14
+ * Minor enhancements
15
+
16
+ * Added #amount_pages to a paginated collection. (Matt Aimonetti)
17
+
1
18
  == 0.31
2
19
 
3
20
  * Major enhancements
@@ -0,0 +1,35 @@
1
+ module RestClientAdapter
2
+
3
+ module API
4
+ def proxy=(url)
5
+ RestClient.proxy = url
6
+ end
7
+
8
+ def proxy
9
+ RestClient.proxy
10
+ end
11
+
12
+ def get(uri, headers={})
13
+ RestClient.get(uri, headers)
14
+ end
15
+
16
+ def post(uri, payload, headers={})
17
+ RestClient.post(uri, payload, headers)
18
+ end
19
+
20
+ def put(uri, payload, headers={})
21
+ RestClient.put(uri, payload, headers)
22
+ end
23
+
24
+ def delete(uri, headers={})
25
+ RestClient.delete(uri, headers)
26
+ end
27
+
28
+ def copy(uri, headers)
29
+ RestClient::Request.execute( :method => :copy,
30
+ :url => uri,
31
+ :headers => headers)
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,48 @@
1
+ require 'couchrest/core/adapters/restclient'
2
+
3
+ # Abstraction layet for HTTP communications.
4
+ #
5
+ # By defining a basic API that CouchRest is relying on,
6
+ # it allows for easy experimentations and implementations of various libraries.
7
+ #
8
+ # Most of the API is based on the RestClient API that was used in the early version of CouchRest.
9
+ #
10
+ module HttpAbstraction
11
+
12
+ # here is the list of exception expected by CouchRest
13
+ # please convert the underlying errors in this set of known
14
+ # exceptions.
15
+ class ResourceNotFound < StandardError; end
16
+ class RequestFailed < StandardError; end
17
+ class RequestTimeout < StandardError; end
18
+ class ServerBrokeConnection < StandardError; end
19
+ class Conflict < StandardError; end
20
+
21
+
22
+ # # Here is the API you need to implement if you want to write a new adapter
23
+ # # See adapters/restclient.rb for more information.
24
+ #
25
+ # def self.proxy=(url)
26
+ # end
27
+ #
28
+ # def self.proxy
29
+ # end
30
+ #
31
+ # def self.get(uri, headers=nil)
32
+ # end
33
+ #
34
+ # def self.post(uri, payload, headers=nil)
35
+ # end
36
+ #
37
+ # def self.put(uri, payload, headers=nil)
38
+ # end
39
+ #
40
+ # def self.delete(uri, headers=nil)
41
+ # end
42
+ #
43
+ # def self.copy(uri, headers)
44
+ # end
45
+
46
+ end
47
+
48
+ HttpAbstraction.extend(RestClientAdapter::API)
@@ -226,7 +226,7 @@ module CouchRest
226
226
  # end
227
227
 
228
228
  name = "_conditional_callback_#{@kind}_#{next_id}"
229
- txt, line = <<-RUBY_EVAL, __LINE__
229
+ txt, line = <<-RUBY_EVAL, __LINE__ + 1
230
230
  def #{name}(halted)
231
231
  #{@compiled_options[0] || "if true"} && !halted
232
232
  #{@filter} do
@@ -388,7 +388,7 @@ module CouchRest
388
388
  body = send("_#{symbol}_callback").
389
389
  compile(nil, :terminator => send("_#{symbol}_terminator"))
390
390
 
391
- body, line = <<-RUBY_EVAL, __LINE__
391
+ body, line = <<-RUBY_EVAL, __LINE__ + 1
392
392
  def _run_#{symbol}_callbacks(key = nil, &blk)
393
393
  if key
394
394
  name = "_run__\#{self.class.name.hash.abs}__#{symbol}__\#{key.hash.abs}__callbacks"
@@ -83,6 +83,8 @@ module CouchRest
83
83
 
84
84
  DEFAULT_PAGE = 1
85
85
  DEFAULT_PER_PAGE = 30
86
+
87
+ attr_accessor :amount_pages
86
88
 
87
89
  # Create a new CollectionProxy to represent the specified view. If a
88
90
  # container class is specified, the proxy will create an object of the
@@ -110,7 +112,8 @@ module CouchRest
110
112
  # See Collection.paginate
111
113
  def paginate(options = {})
112
114
  page, per_page = parse_options(options)
113
- results = @database.view(@view_name, pagination_options(page, per_page))
115
+ results = @database.view(@view_name, pagination_options(page, per_page))
116
+ @amount_pages ||= (results['total_rows'].to_f / per_page.to_f).ceil
114
117
  remember_where_we_left_off(results, page)
115
118
  convert_to_container_array(results)
116
119
  end
@@ -27,7 +27,7 @@ module CouchRest
27
27
  class IncludeError < StandardError; end
28
28
 
29
29
  def self.included(base)
30
- base.class_eval <<-EOS, __FILE__, __LINE__
30
+ base.class_eval <<-EOS, __FILE__, __LINE__ + 1
31
31
  extlib_inheritable_accessor(:properties) unless self.respond_to?(:properties)
32
32
  self.properties ||= []
33
33
  EOS
@@ -144,14 +144,14 @@ module CouchRest
144
144
  # defines the getter for the property (and optional aliases)
145
145
  def create_property_getter(property)
146
146
  # meth = property.name
147
- class_eval <<-EOS, __FILE__, __LINE__
147
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
148
148
  def #{property.name}
149
149
  self['#{property.name}']
150
150
  end
151
151
  EOS
152
152
 
153
153
  if property.alias
154
- class_eval <<-EOS, __FILE__, __LINE__
154
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
155
155
  alias #{property.alias.to_sym} #{property.name.to_sym}
156
156
  EOS
157
157
  end
@@ -50,7 +50,7 @@ module CouchRest
50
50
 
51
51
  def self.included(base)
52
52
  base.extlib_inheritable_accessor(:auto_validation)
53
- base.class_eval <<-EOS, __FILE__, __LINE__
53
+ base.class_eval <<-EOS, __FILE__, __LINE__ + 1
54
54
  # Callbacks
55
55
  define_callbacks :validate
56
56
 
@@ -74,7 +74,7 @@ module CouchRest
74
74
  EOS
75
75
 
76
76
  base.extend(ClassMethods)
77
- base.class_eval <<-EOS, __FILE__, __LINE__
77
+ base.class_eval <<-EOS, __FILE__, __LINE__ + 1
78
78
  define_callbacks :validate
79
79
  if method_defined?(:_run_save_callbacks)
80
80
  set_callback :save, :before, :check_validations
@@ -210,7 +210,7 @@ module CouchRest
210
210
  def create_context_instance_methods(context)
211
211
  name = "valid_for_#{context.to_s}?" # valid_for_signup?
212
212
  if !self.instance_methods.include?(name)
213
- class_eval <<-EOS, __FILE__, __LINE__
213
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
214
214
  def #{name} # def valid_for_signup?
215
215
  valid?('#{context.to_s}'.to_sym) # valid?('signup'.to_sym)
216
216
  end # end
@@ -21,7 +21,7 @@ module CouchRest
21
21
 
22
22
  def self.inherited(subklass)
23
23
  subklass.send(:include, CouchRest::Mixins::Properties)
24
- subklass.class_eval <<-EOS, __FILE__, __LINE__
24
+ subklass.class_eval <<-EOS, __FILE__, __LINE__ + 1
25
25
  def self.inherited(subklass)
26
26
  subklass.properties = self.properties.dup
27
27
  end
@@ -76,7 +76,7 @@ module CouchRest
76
76
  # on the document whenever saving occurs. CouchRest uses a pretty
77
77
  # decent time format by default. See Time#to_json
78
78
  def self.timestamps!
79
- class_eval <<-EOS, __FILE__, __LINE__
79
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
80
80
  property(:updated_at, :read_only => true, :cast_as => 'Time', :auto_validation => false)
81
81
  property(:created_at, :read_only => true, :cast_as => 'Time', :auto_validation => false)
82
82
 
data/lib/couchrest.rb CHANGED
@@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
28
28
 
29
29
  # = CouchDB, close to the metal
30
30
  module CouchRest
31
- VERSION = '0.30' unless self.const_defined?("VERSION")
31
+ VERSION = '0.31' unless self.const_defined?("VERSION")
32
32
 
33
33
  autoload :Server, 'couchrest/core/server'
34
34
  autoload :Database, 'couchrest/core/database'
@@ -365,6 +365,11 @@ describe "ExtendedDocument views" do
365
365
  articles.paginated_each(:per_page => 3) do |a|
366
366
  a.should_not be_nil
367
367
  end
368
+ end
369
+ it "should have the amount of paginated pages" do
370
+ articles = Article.by_date :key => Date.today
371
+ articles.paginate(:per_page => 3)
372
+ articles.amount_pages.should == 3
368
373
  end
369
374
  it "should provide a class method to access the collection directly" do
370
375
  articles = Article.collection_proxy_for('Article', 'by_date', :descending => true,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sporkd-couchrest
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.30"
4
+ version: "0.31"
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Chris Anderson
@@ -71,9 +71,12 @@ files:
71
71
  - lib/couchrest/commands/generate.rb
72
72
  - lib/couchrest/commands/push.rb
73
73
  - lib/couchrest/core
74
+ - lib/couchrest/core/adapters
75
+ - lib/couchrest/core/adapters/restclient.rb
74
76
  - lib/couchrest/core/database.rb
75
77
  - lib/couchrest/core/design.rb
76
78
  - lib/couchrest/core/document.rb
79
+ - lib/couchrest/core/http_abstraction.rb
77
80
  - lib/couchrest/core/response.rb
78
81
  - lib/couchrest/core/server.rb
79
82
  - lib/couchrest/core/view.rb