lib/devdnsd/rule.rb in devdnsd-2.2.0 vs lib/devdnsd/rule.rb in devdnsd-2.3.0
- old
+ new
@@ -33,21 +33,21 @@
# @param type [Symbol] The type of request to match.
# @param options [Hash] A list of options for the request.
# @param block [Proc] An optional block to compute the reply instead of using the `reply` parameter.
# @see .create
def initialize(match = /.+/, reply = "127.0.0.1", type = :A, options = {}, &block)
- self.i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
+ i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
self.i18n = options[:locale]
setup(match, reply, type, options, block)
validate_rule
end
# Returns the resource class(es) for the current rule.
#
# @return [Array|Class] The class(es) for the current rule.
def resource_class
- classes = @type.ensure_array.collect {|cls| self.class.symbol_to_resource_class(cls, options[:locale]) }.compact.uniq
+ classes = @type.ensure_array(nil, true, true) {|cls| self.class.symbol_to_resource_class(cls, options[:locale]) }
classes.length == 1 ? classes.first : classes
end
# Checks if the rule is a regexp.
#
@@ -66,11 +66,11 @@
# Matches a hostname to the rule.
#
# @param hostname [String] The hostname to match.
# @return [MatchData|Boolean|Nil] Return `true` or MatchData (if the pattern is a regexp) if the rule matches, `false` or `nil` otherwise.
def match_host(hostname)
- self.is_regexp? ? @match.match(hostname) : (@match == hostname)
+ is_regexp? ? @match.match(hostname) : (@match == hostname)
end
# Creates a new rule.
#
# @param match [String|Regexp] The pattern to match.
@@ -79,11 +79,11 @@
# @param options [Hash] A list of options for the request.
# @param block [Proc] An optional block to compute the reply instead of using the `reply_or_type` parameter. In this case `reply_or_type` is used for the type of the request and `type` is ignored.
# @return [Rule] The new rule.
def self.create(match, reply_or_type = nil, type = nil, options = {}, &block)
validate_options(reply_or_type, options, block, Lazier::Localizer.new(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"), options.is_a?(Hash) ? options[:locale] : nil))
- setup(self.new(match), reply_or_type, type, options, block)
+ setup(new(match), reply_or_type, type, options, block)
end
# Converts a class to the correspondent symbol.
#
# @param klass [Class] The class to convert.
@@ -123,11 +123,11 @@
@block = block
end
# Validates a newly created rule.
def validate_rule
- raise(DevDNSd::Errors::InvalidRule.new(self.i18n.rule_invalid_call)) if @reply.blank? && @block.nil?
- raise(DevDNSd::Errors::InvalidRule.new(self.i18n.rule_invalid_options)) if !@options.is_a?(::Hash)
+ raise(DevDNSd::Errors::InvalidRule.new(i18n.rule_invalid_call)) if @reply.blank? && @block.nil?
+ raise(DevDNSd::Errors::InvalidRule.new(i18n.rule_invalid_options)) if !@options.is_a?(::Hash)
end
# Setups a new rule.
#
# @param rv [Rule] The rule that is been created.