Module: Rack::Alpaca
- Defined in:
- lib/rack/alpaca.rb,
lib/rack/alpaca/version.rb
Constant Summary collapse
- VERSION =
'1.1.5'
Class Attribute Summary collapse
-
.blacklist ⇒ Object
readonly
Returns the value of attribute blacklist.
-
.default ⇒ Object
Returns the value of attribute default.
-
.whitelist ⇒ Object
readonly
Returns the value of attribute whitelist.
Class Method Summary collapse
Class Attribute Details
.blacklist ⇒ Object (readonly)
Returns the value of attribute blacklist.
5 6 7 |
# File 'lib/rack/alpaca.rb', line 5 def blacklist @blacklist end |
.default ⇒ Object
Returns the value of attribute default.
6 7 8 |
# File 'lib/rack/alpaca.rb', line 6 def default @default end |
.whitelist ⇒ Object (readonly)
Returns the value of attribute whitelist.
5 6 7 |
# File 'lib/rack/alpaca.rb', line 5 def whitelist @whitelist end |
Class Method Details
.call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/alpaca.rb', line 19 def call (env) req = Rack::Request.new(env) if whitelisted?('whitelist', req) @app.call(env) elsif blacklisted?('blacklist', req) [503, { "Content-Type"=>"text/plain" }, ["Request blocked\n"]] else default_strategy(env) end end |
.new(app) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rack/alpaca.rb', line 8 def new (app) @@config ||= YAML.load_file('config/alpaca.yml') @app = app @whitelist ||= Hash[@@config['whitelist'].map { |ip| [IPAddr.new(ip), true] }].freeze @blacklist ||= Hash[@@config['blacklist'].map { |ip| [IPAddr.new(ip), true] }].freeze @default = @@config['default'] self end |