lib/nanoc/extra/chick.rb in nanoc-3.7.4 vs lib/nanoc/extra/chick.rb in nanoc-3.7.5
- old
+ new
@@ -3,28 +3,25 @@
require 'net/http'
require 'rack'
require 'rack/cache'
module Nanoc::Extra
-
# @deprecated Use a HTTP library such as
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
# [Curb](https://github.com/taf2/curb) instead.
module CHiCk
-
# @deprecated Use a HTTP library such as
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
# [Curb](https://github.com/taf2/curb) instead.
class Client
-
DEFAULT_OPTIONS = {
- :cache => {
- :metastore => 'file:tmp/rack/cache.meta',
- :entitystore => 'file:tmp/rack/cache.body'
+ cache: {
+ metastore: 'file:tmp/rack/cache.meta',
+ entitystore: 'file:tmp/rack/cache.body'
},
- :cache_controller => {
- :max_age => 60
+ cache_controller: {
+ max_age: 60
}
}
def initialize(options = {})
# Get options
@@ -35,17 +32,17 @@
def get(url)
# Build app
options = @options
@app ||= Rack::Builder.new do
- use Rack::Cache, options[:cache].merge(:verbose => true)
+ use Rack::Cache, options[:cache].merge(verbose: true)
use Nanoc::Extra::CHiCk::CacheController, options[:cache_controller]
run Nanoc::Extra::CHiCk::RackClient
end
# Build environment for request
- env = Rack::MockRequest.env_for(url, :method => 'GET')
+ env = Rack::MockRequest.env_for(url, method: 'GET')
# Fetch
puts "[CHiCk] Fetching #{url}..." if $DEBUG
status, headers, body_parts = @app.call(env)
puts "[CHiCk] #{url}: #{headers['X-Rack-Cache']}" if $DEBUG
@@ -55,18 +52,16 @@
body_parts.each { |part| body << part }
# Done
[status, headers, body]
end
-
end
# @deprecated Use a HTTP library such as
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
# [Curb](https://github.com/taf2/curb) instead.
class CacheController
-
def initialize(app, options = {})
@app = app
@options = options
end
@@ -75,18 +70,16 @@
unless res[1].key?('Cache-Control') || res[1].key?('Expires')
res[1]['Cache-Control'] = "max-age=#{@options[:max_age]}"
end
res
end
-
end
# @deprecated Use a HTTP library such as
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
# [Curb](https://github.com/taf2/curb) instead.
class RackClient
-
METHOD_TO_CLASS_MAPPING = {
'DELETE' => Net::HTTP::Delete,
'GET' => Net::HTTP::Get,
'HEAD' => Net::HTTP::Head,
'POST' => Net::HTTP::Post,
@@ -117,11 +110,8 @@
response.to_hash.reduce({}) { |m, (k, v)| m.merge(k => v[0]) },
[response.body]
]
end
end
-
end
-
end
-
end