Class: Rack::IpRestrictor::Config
- Inherits:
-
Object
- Object
- Rack::IpRestrictor::Config
- Defined in:
- lib/rack_ip_restrictor/config.rb
Overview
Configuration class for the IpRestrictor
Instance Attribute Summary (collapse)
-
- (Object) ip_groups
Returns the value of attribute ip_groups.
-
- (Object) response
Returns the value of attribute response.
-
- (Object) restrictions
Returns the value of attribute restrictions.
Instance Method Summary (collapse)
-
- (Config) initialize
constructor
A new instance of Config.
-
- (IpGroup) ips_for(name, &block)
Sets and gets IP addresses for a named group.
-
- (Object) respond_with(response)
Overwrites the default response.
-
- (Object) restrict(*args)
Adds a restriction.
Constructor Details
- (Config) initialize
A new instance of Config
18 19 20 21 22 23 24 25 26 |
# File 'lib/rack_ip_restrictor/config.rb', line 18 def initialize @ip_groups = {} @restrictions = [] @response = [ 403, {'Content-Type' => 'text/html'}, '' ] end |
Instance Attribute Details
- (Object) ip_groups
Returns the value of attribute ip_groups
16 17 18 |
# File 'lib/rack_ip_restrictor/config.rb', line 16 def ip_groups @ip_groups end |
- (Object) response
Returns the value of attribute response
16 17 18 |
# File 'lib/rack_ip_restrictor/config.rb', line 16 def response @response end |
- (Object) restrictions
Returns the value of attribute restrictions
16 17 18 |
# File 'lib/rack_ip_restrictor/config.rb', line 16 def restrictions @restrictions end |
Instance Method Details
- (IpGroup) ips_for(name, &block)
Sets and gets IP addresses for a named group
38 39 40 41 42 43 44 45 46 |
# File 'lib/rack_ip_restrictor/config.rb', line 38 def ips_for(name, &block) if block_given? @ip_groups[name] = IpGroup.new @ip_groups[name].instance_eval &block @ip_groups[name] else @ip_groups[name] end end |
- (Object) respond_with(response)
Overwrites the default response. Same format as a middleware response.
31 32 33 |
# File 'lib/rack_ip_restrictor/config.rb', line 31 def respond_with(response) @response = response end |
- (Object) restrict(*args)
Adds a restriction
50 51 52 |
# File 'lib/rack_ip_restrictor/config.rb', line 50 def restrict(*args) @restrictions << Restriction.new(*args) end |