lib/spidr/sanitizers.rb in spidr-0.3.1 vs lib/spidr/sanitizers.rb in spidr-0.3.2
- old
+ new
@@ -4,45 +4,17 @@
#
# The {Sanitizers} module adds methods to {Agent} which control the
# sanitation of incoming links.
#
module Sanitizers
- def self.included(base)
- base.module_eval do
- # Specifies whether the Agent will strip URI fragments
- attr_accessor :strip_fragments
+ # Specifies whether the Agent will strip URI fragments
+ attr_accessor :strip_fragments
- # Specifies whether the Agent will strip URI queries
- attr_accessor :strip_query
- end
- end
+ # Specifies whether the Agent will strip URI queries
+ attr_accessor :strip_query
#
- # Initializes the Sanitizer rules.
- #
- # @param [Hash] options
- # Additional options.
- #
- # @option options [Boolean] :strip_fragments (true)
- # Specifies whether or not to strip the fragment component from URLs.
- #
- # @option options [Boolean] :strip_query (false)
- # Specifies whether or not to strip the query component from URLs.
- #
- # @since 0.2.2
- #
- def initialize(options={})
- @strip_fragments = true
-
- if options.has_key?(:strip_fragments)
- @strip_fragments = options[:strip_fragments]
- end
-
- @strip_query = (options[:strip_query] || false)
- end
-
- #
# Sanitizes a URL based on filtering options.
#
# @param [URI::HTTP, URI::HTTPS, String] url
# The URL to be sanitized
#
@@ -56,8 +28,29 @@
url.fragment = nil if @strip_fragments
url.query = nil if @strip_query
return url
+ end
+
+ protected
+
+ #
+ # Initializes the Sanitizer rules.
+ #
+ # @param [Hash] options
+ # Additional options.
+ #
+ # @option options [Boolean] :strip_fragments (true)
+ # Specifies whether or not to strip the fragment component from URLs.
+ #
+ # @option options [Boolean] :strip_query (false)
+ # Specifies whether or not to strip the query component from URLs.
+ #
+ # @since 0.2.2
+ #
+ def initialize_sanitizers(options={})
+ @strip_fragments = options.fetch(:strip_fragments,true)
+ @strip_query = options.fetch(:strip_query,false)
end
end
end