active_resource_extensions 0.0.1
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +88 -0
- data/Rakefile +5 -0
- data/active_resource_extensions.gemspec +24 -0
- data/lib/active_resource_extensions/graceful_errors.rb +23 -0
- data/lib/active_resource_extensions/railtie.rb +13 -0
- data/lib/active_resource_extensions/version.rb +3 -0
- data/lib/active_resource_extensions.rb +11 -0
- data/spec/active_resource_extensions/graceful_errors_spec.rb +42 -0
- data/spec/spec_helper.rb +2 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
active_resource_extensions (0.0.1)
|
5
|
+
rails (~> 3.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionmailer (3.0.3)
|
12
|
+
actionpack (= 3.0.3)
|
13
|
+
mail (~> 2.2.9)
|
14
|
+
actionpack (3.0.3)
|
15
|
+
activemodel (= 3.0.3)
|
16
|
+
activesupport (= 3.0.3)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
erubis (~> 2.6.6)
|
19
|
+
i18n (~> 0.4)
|
20
|
+
rack (~> 1.2.1)
|
21
|
+
rack-mount (~> 0.6.13)
|
22
|
+
rack-test (~> 0.5.6)
|
23
|
+
tzinfo (~> 0.3.23)
|
24
|
+
activemodel (3.0.3)
|
25
|
+
activesupport (= 3.0.3)
|
26
|
+
builder (~> 2.1.2)
|
27
|
+
i18n (~> 0.4)
|
28
|
+
activerecord (3.0.3)
|
29
|
+
activemodel (= 3.0.3)
|
30
|
+
activesupport (= 3.0.3)
|
31
|
+
arel (~> 2.0.2)
|
32
|
+
tzinfo (~> 0.3.23)
|
33
|
+
activeresource (3.0.3)
|
34
|
+
activemodel (= 3.0.3)
|
35
|
+
activesupport (= 3.0.3)
|
36
|
+
activesupport (3.0.3)
|
37
|
+
arel (2.0.6)
|
38
|
+
builder (2.1.2)
|
39
|
+
diff-lcs (1.1.2)
|
40
|
+
erubis (2.6.6)
|
41
|
+
abstract (>= 1.0.0)
|
42
|
+
i18n (0.5.0)
|
43
|
+
mail (2.2.12)
|
44
|
+
activesupport (>= 2.3.6)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.16)
|
49
|
+
polyglot (0.3.1)
|
50
|
+
rack (1.2.1)
|
51
|
+
rack-mount (0.6.13)
|
52
|
+
rack (>= 1.0.0)
|
53
|
+
rack-test (0.5.6)
|
54
|
+
rack (>= 1.0)
|
55
|
+
rails (3.0.3)
|
56
|
+
actionmailer (= 3.0.3)
|
57
|
+
actionpack (= 3.0.3)
|
58
|
+
activerecord (= 3.0.3)
|
59
|
+
activeresource (= 3.0.3)
|
60
|
+
activesupport (= 3.0.3)
|
61
|
+
bundler (~> 1.0)
|
62
|
+
railties (= 3.0.3)
|
63
|
+
railties (3.0.3)
|
64
|
+
actionpack (= 3.0.3)
|
65
|
+
activesupport (= 3.0.3)
|
66
|
+
rake (>= 0.8.7)
|
67
|
+
thor (~> 0.14.4)
|
68
|
+
rake (0.8.7)
|
69
|
+
rspec (2.3.0)
|
70
|
+
rspec-core (~> 2.3.0)
|
71
|
+
rspec-expectations (~> 2.3.0)
|
72
|
+
rspec-mocks (~> 2.3.0)
|
73
|
+
rspec-core (2.3.0)
|
74
|
+
rspec-expectations (2.3.0)
|
75
|
+
diff-lcs (~> 1.1.2)
|
76
|
+
rspec-mocks (2.3.0)
|
77
|
+
thor (0.14.6)
|
78
|
+
treetop (1.4.9)
|
79
|
+
polyglot (>= 0.3.1)
|
80
|
+
tzinfo (0.3.23)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
active_resource_extensions!
|
87
|
+
rails (~> 3.0.0)
|
88
|
+
rspec (~> 2.3.0)
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "active_resource_extensions/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "active_resource_extensions"
|
7
|
+
s.version = ActiveResourceExtensions::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Paul McMahon"]
|
10
|
+
s.email = ["paul@mobalean.com"]
|
11
|
+
s.homepage = "https://github.com/mobalean/active_resource_extensions"
|
12
|
+
s.summary = %q{Extensions to active resource}
|
13
|
+
s.description = %q{A collection of extensions for active resource}
|
14
|
+
|
15
|
+
s.rubyforge_project = "active_resource_extensions"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'rails', "~> 3.0.0"
|
23
|
+
s.add_development_dependency 'rspec', "~> 2.3.0"
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module ActiveResourceExtensions
|
4
|
+
module GracefulErrors
|
5
|
+
private
|
6
|
+
|
7
|
+
def find_every(options)
|
8
|
+
begin
|
9
|
+
super
|
10
|
+
rescue Errno::ECONNREFUSED, ActiveResource::TimeoutError => exception
|
11
|
+
log_error(exception)
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def log_error(exception)
|
17
|
+
message = "\n#{exception.class} (#{exception.message}):\n"
|
18
|
+
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
|
19
|
+
message << " " << Rails.backtrace_cleaner.clean(exception.backtrace, :silent).join("\n ")
|
20
|
+
Rails.logger.fatal("#{message}\n\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module ActiveResourceExtensions
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "active_resource_extensions.extend.active_resource" do |app|
|
6
|
+
ActiveResource::Base.class_eval do
|
7
|
+
class << self
|
8
|
+
include ActiveResourceExtensions
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'active_resource_extensions/railtie'
|
2
|
+
module ActiveResourceExtensions
|
3
|
+
autoload :GracefulErrors, "active_resource_extensions/graceful_errors"
|
4
|
+
def inherited(subclass)
|
5
|
+
subclass.class_eval do
|
6
|
+
class << self
|
7
|
+
include ActiveResourceExtensions::GracefulErrors
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_resource'
|
3
|
+
|
4
|
+
describe ActiveResourceExtensions::GracefulErrors do
|
5
|
+
before do
|
6
|
+
mock = Class.new(ActiveResource::Base)
|
7
|
+
mock.class_eval do
|
8
|
+
class << self
|
9
|
+
attr_accessor :exception
|
10
|
+
|
11
|
+
def find_every(option)
|
12
|
+
raise exception
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
@resource = Class.new(mock)
|
17
|
+
@resource.class_eval do
|
18
|
+
class << self
|
19
|
+
include ActiveResourceExtensions::GracefulErrors
|
20
|
+
end
|
21
|
+
end
|
22
|
+
Rails.logger = mock("logger")
|
23
|
+
Rails.logger.stub!(:fatal)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "Errno::ECONNREFUSED thrown" do
|
27
|
+
before { @resource.exception = Errno::ECONNREFUSED }
|
28
|
+
it("first should return nil") { @resource.first.should be_nil }
|
29
|
+
it("all should return empty array") { @resource.all.should be_empty }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "ActiveResource::TimeoutError thrown" do
|
33
|
+
before { @resource.exception = ActiveResource::TimeoutError.new("message") }
|
34
|
+
it("first should return nil") { @resource.first.should be_nil }
|
35
|
+
it("all should return empty array") { @resource.all.should be_empty }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "arbitrary exception thrown" do
|
39
|
+
before { @resource.exception = "arbitrary" }
|
40
|
+
it("first should raise exception") { lambda { @resource.first }.should raise_error }
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_resource_extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Paul McMahon
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-10 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 0
|
50
|
+
version: 2.3.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: A collection of extensions for active resource
|
54
|
+
email:
|
55
|
+
- paul@mobalean.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- Rakefile
|
67
|
+
- active_resource_extensions.gemspec
|
68
|
+
- lib/active_resource_extensions.rb
|
69
|
+
- lib/active_resource_extensions/graceful_errors.rb
|
70
|
+
- lib/active_resource_extensions/railtie.rb
|
71
|
+
- lib/active_resource_extensions/version.rb
|
72
|
+
- spec/active_resource_extensions/graceful_errors_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: https://github.com/mobalean/active_resource_extensions
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: active_resource_extensions
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Extensions to active resource
|
108
|
+
test_files:
|
109
|
+
- spec/active_resource_extensions/graceful_errors_spec.rb
|
110
|
+
- spec/spec_helper.rb
|