activeresource-response 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Igor Fedoronchuk.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -10,12 +10,19 @@ Such functionallity can be used for easily implementing pagination in a REST API
10
10
  == How to use?
11
11
  Add dependency to your Gemfile
12
12
 
13
- gem "activeresource-response", "~> 0.0.5"
13
+ gem "activeresource-response", "~> 0.0.7"
14
14
 
15
- Just open your ActiveResource class and add
15
+ Just open your ActiveResource class and add
16
16
 
17
17
  add_response_method :your_method_name
18
18
 
19
+ You can add method to ActiveResource::Base to use it in all subclasses
20
+
21
+ class ActiveResource::Base
22
+ add_response_method :my_response
23
+ end
24
+
25
+
19
26
  == Full example of usage with kaminari gem
20
27
 
21
28
  Rest Client
@@ -24,7 +31,7 @@ Rest Client
24
31
  self.format = :json
25
32
  self.site = 'http://0.0.0.0:3000/'
26
33
  self.element_name = "order"
27
- add_response_method :http_response # our new method
34
+ add_response_method :http_response # our new method for returned objects
28
35
  end
29
36
 
30
37
  Server Side
@@ -1,5 +1,5 @@
1
1
  require "activeresource-response/version"
2
2
  require "activeresource-response/connection"
3
- require "activeresource-response/add_response_method"
3
+ require "activeresource-response/response_method"
4
4
  ActiveResource::Connection.send :include, ActiveresourceResponse::Connection
5
- ActiveResource::Base.send :include, ActiveresourceResponse::AddResponseMethod
5
+ ActiveResource::Base.send :include, ActiveresourceResponse::ResponseMethod
@@ -4,11 +4,11 @@ module ActiveresourceResponse
4
4
  base.class_eval do
5
5
  alias_method :origin_handle_response, :handle_response
6
6
  def handle_response(response)
7
- Thread.current['ActiveResource::Base.http_response'] = response
7
+ Thread.current[:ActiveResourceHttpResponse] = response
8
8
  origin_handle_response(response)
9
9
  end
10
10
  def http_response
11
- Thread.current['ActiveResource::Base.http_response']
11
+ Thread.current[:ActiveResourceHttpResponse]
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,41 @@
1
+ module ActiveresourceResponse
2
+
3
+ module ResponseMethod
4
+
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def add_response_method(method_name = :http_response)
11
+
12
+ remove_response_method if methods.include?(:find_without_http_response)
13
+ [:find, :get].each do |method|
14
+ instance_eval <<-EOS
15
+ alias #{method}_without_http_response #{method}
16
+ def #{method}(*arguments)
17
+ result = #{method}_without_http_response(*arguments)
18
+ result.instance_variable_set(:@http_response, connection.http_response)
19
+ def result.#{method_name}
20
+ @http_response
21
+ end
22
+ result
23
+ end
24
+ EOS
25
+ end
26
+ end
27
+
28
+ def remove_response_method
29
+ [:find, :get].each do |method|
30
+ instance_eval <<-EOS
31
+ undef :#{method}
32
+ alias :#{method} :#{method}_without_http_response
33
+ undef :#{method}_without_http_response
34
+ EOS
35
+
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveresourceResponse
2
2
  module Version
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource-response
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.6
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 7
9
+ version: 0.0.7
6
10
  platform: ruby
7
11
  authors:
8
12
  - Igor Fedoronchuk
@@ -10,16 +14,19 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2012-02-21 00:00:00 Z
17
+ date: 2012-03-13 00:00:00 +02:00
18
+ default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activeresource
17
22
  prerelease: false
18
23
  requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
23
30
  version: "3.0"
24
31
  type: :runtime
25
32
  version_requirements: *id001
@@ -35,13 +42,15 @@ extra_rdoc_files: []
35
42
  files:
36
43
  - .gitignore
37
44
  - Gemfile
45
+ - LICENSE
38
46
  - README.rdoc
39
47
  - Rakefile
40
48
  - activeresource-response.gemspec
41
49
  - lib/activeresource-response.rb
42
- - lib/activeresource-response/add_response_method.rb
43
50
  - lib/activeresource-response/connection.rb
51
+ - lib/activeresource-response/response_method.rb
44
52
  - lib/activeresource-response/version.rb
53
+ has_rdoc: true
45
54
  homepage: https://github.com/Fivell/activeresource-response
46
55
  licenses: []
47
56
 
@@ -51,21 +60,23 @@ rdoc_options: []
51
60
  require_paths:
52
61
  - lib
53
62
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
63
  requirements:
56
64
  - - ">="
57
65
  - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
58
68
  version: "0"
59
69
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
70
  requirements:
62
71
  - - ">="
63
72
  - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
64
75
  version: "0"
65
76
  requirements: []
66
77
 
67
78
  rubyforge_project: activeresource-response
68
- rubygems_version: 1.8.13
79
+ rubygems_version: 1.3.6
69
80
  signing_key:
70
81
  specification_version: 3
71
82
  summary: activeresource extension
@@ -1,24 +0,0 @@
1
- module ActiveresourceResponse
2
- module AddResponseMethod
3
- def self.included(base)
4
- base.extend ClassMethods
5
- end
6
- module ClassMethods
7
- def add_response_method(method_name = 'http_response')
8
- [:find, :get].each do |method|
9
- class_eval <<-EOS
10
- class << self
11
- alias_method :origin_#{method}, :#{method}
12
- def #{method}(*arguments)
13
- result = origin_#{method}(*arguments)
14
- result.class_eval("attr_reader :#{method_name}")
15
- result.instance_variable_set(:"@#{method_name}", connection.http_response)
16
- result
17
- end
18
- end
19
- EOS
20
- end
21
- end
22
- end
23
- end
24
- end