rack-restfolia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/rack/restfolia.rb +10 -0
- data/lib/rack/restfolia/cache.rb +25 -0
- data/lib/rack/restfolia/middleware.rb +16 -0
- data/lib/rack/restfolia/monkey_patch.rb +17 -0
- data/lib/rack/restfolia/version.rb +5 -0
- data/rack-restfolia.gemspec +23 -0
- data/spec/cache_spec.rb +27 -0
- data/spec/middleware_spec.rb +24 -0
- data/spec/spec_helper.rb +23 -0
- metadata +130 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@rack-restfolia --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Fred
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rack::Restfolia
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rack-restfolia'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rack-restfolia
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rack
|
2
|
+
module Restfolia
|
3
|
+
module Cache
|
4
|
+
class << self
|
5
|
+
def storage
|
6
|
+
@hash ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(url)
|
10
|
+
storage[url]
|
11
|
+
end
|
12
|
+
|
13
|
+
def store(url, data)
|
14
|
+
storage[url] = data
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear
|
18
|
+
@hash = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
alias :start :clear
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'restfolia'
|
2
|
+
|
3
|
+
module Restfolia
|
4
|
+
class EntryPoint
|
5
|
+
alias :get_original :get
|
6
|
+
|
7
|
+
def get(params = nil)
|
8
|
+
if cached_response = Rack::Restfolia::Cache.get(@url)
|
9
|
+
cached_response
|
10
|
+
else
|
11
|
+
response = get_original(params)
|
12
|
+
Rack::Restfolia::Cache.store(@url, response)
|
13
|
+
response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rack/restfolia/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Fred", "Felipe Oliveira"]
|
6
|
+
gem.email = ["fpaula@gmail.com", "felipecvo@gmail.com"]
|
7
|
+
gem.description = %q{Restfolia extension to avoid duplicated requests}
|
8
|
+
gem.summary = %q{Restfolia extension to avoid duplicated requests}
|
9
|
+
gem.homepage = "https://github.com/fpaula/rack-restfolia"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rack-restfolia"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Rack::Restfolia::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'restfolia'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'rack-test'
|
22
|
+
gem.add_development_dependency 'webmock'
|
23
|
+
end
|
data/spec/cache_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::Restfolia::Cache do
|
4
|
+
context 'get stored objects' do
|
5
|
+
subject { Rack::Restfolia::Cache.get('http://www.example.com') }
|
6
|
+
before { Rack::Restfolia::Cache.store('http://www.example.com', 'restfolia response data') }
|
7
|
+
it { should eq 'restfolia response data' }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'clear storage when start' do
|
11
|
+
subject { Rack::Restfolia::Cache.get('http://www.example.com') }
|
12
|
+
before do
|
13
|
+
Rack::Restfolia::Cache.store('http://www.example.com', 'restfolia response data')
|
14
|
+
Rack::Restfolia::Cache.start
|
15
|
+
end
|
16
|
+
it { should be_nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'clear storage' do
|
20
|
+
subject { Rack::Restfolia::Cache.get('http://www.example.com') }
|
21
|
+
before do
|
22
|
+
Rack::Restfolia::Cache.store('http://www.example.com', 'restfolia response data')
|
23
|
+
Rack::Restfolia::Cache.clear
|
24
|
+
end
|
25
|
+
it { should be_nil }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::Restfolia::Middleware do
|
4
|
+
def app
|
5
|
+
Rack::Builder.new do
|
6
|
+
use Rack::Restfolia::Middleware
|
7
|
+
run AppTest.new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should cache requests" do
|
12
|
+
stub = stub_request(:get, "www.example.com").to_return(:headers => {:content_type => 'application/json'}, :body => '[]')
|
13
|
+
get "/"
|
14
|
+
stub.should have_been_requested.once
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class AppTest
|
19
|
+
def call(env)
|
20
|
+
Restfolia.at('http://www.example.com/').get
|
21
|
+
Restfolia.at('http://www.example.com/').get
|
22
|
+
[200, {'content-type' => 'text'}, []]
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'rack/restfolia'
|
4
|
+
require 'restfolia'
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
9
|
+
# loaded once.
|
10
|
+
#
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
config.include Rack::Test::Methods
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-restfolia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fred
|
9
|
+
- Felipe Oliveira
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-08-16 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: restfolia
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rspec
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rack-test
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: webmock
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
description: Restfolia extension to avoid duplicated requests
|
80
|
+
email:
|
81
|
+
- fpaula@gmail.com
|
82
|
+
- felipecvo@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .rspec
|
89
|
+
- .rvmrc
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/rack/restfolia.rb
|
95
|
+
- lib/rack/restfolia/cache.rb
|
96
|
+
- lib/rack/restfolia/middleware.rb
|
97
|
+
- lib/rack/restfolia/monkey_patch.rb
|
98
|
+
- lib/rack/restfolia/version.rb
|
99
|
+
- rack-restfolia.gemspec
|
100
|
+
- spec/cache_spec.rb
|
101
|
+
- spec/middleware_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/fpaula/rack-restfolia
|
104
|
+
licenses: []
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.8.19
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Restfolia extension to avoid duplicated requests
|
127
|
+
test_files:
|
128
|
+
- spec/cache_spec.rb
|
129
|
+
- spec/middleware_spec.rb
|
130
|
+
- spec/spec_helper.rb
|